From: Thijs K. <ki...@us...> - 2004-03-15 10:29:28
|
Update of /cvsroot/squirrelmail/squirrelmail/functions In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv497/functions Modified Files: Tag: SM-1_4-STABLE abook_local_file.php file_prefs.php strings.php Log Message: Make writing to prefs/abook/calendar files more reliable by handling it the right way when writing fails (error in stead of truncating file). Index: abook_local_file.php =================================================================== RCS file: /cvsroot/squirrelmail/squirrelmail/functions/abook_local_file.php,v retrieving revision 1.22.2.1 retrieving revision 1.22.2.2 diff -u -w -r1.22.2.1 -r1.22.2.2 --- abook_local_file.php 24 Feb 2004 15:57:15 -0000 1.22.2.1 +++ abook_local_file.php 15 Mar 2004 10:20:13 -0000 1.22.2.2 @@ -146,8 +146,8 @@ for($j = 0, $cnt_part=count($rows[$i]) ; $j < $cnt_part ; $j++) { $rows[$i][$j] = $this->quotevalue($rows[$i][$j]); } - $tmpwrite = @fwrite($newfh, join('|', $rows[$i]) . "\n"); - if ($tmpwrite == -1) { + $tmpwrite = sq_fwrite($newfh, join('|', $rows[$i]) . "\n"); + if ($tmpwrite === FALSE) { return $this->set_error($this->filename . '.tmp:' . _("Write failed")); } } @@ -281,17 +281,19 @@ } /* Write */ - $r = fwrite($this->filehandle, $data); + $r = sq_fwrite($this->filehandle, $data); /* Unlock file */ $this->unlock(); - /* Test write result and exit if OK */ - if($r > 0) return true; - + /* Test write result */ + if($r === FALSE) { /* Fail */ $this->set_error(_("Write to addressbook failed")); - return false; + return FALSE; + } + + return TRUE; } /* Delete address */ Index: file_prefs.php =================================================================== RCS file: /cvsroot/squirrelmail/squirrelmail/functions/file_prefs.php,v retrieving revision 1.26.2.3 retrieving revision 1.26.2.4 diff -u -w -r1.26.2.3 -r1.26.2.4 --- file_prefs.php 24 Feb 2004 15:57:15 -0000 1.26.2.3 +++ file_prefs.php 15 Mar 2004 10:20:14 -0000 1.26.2.4 @@ -119,7 +119,7 @@ } foreach ($prefs_cache as $Key => $Value) { if (isset($Value)) { - if ( @fwrite($file, $Key . '=' . $Value . "\n") === FALSE ) { + if ( sq_fwrite($file, $Key . '=' . $Value . "\n") === FALSE ) { logout_error( sprintf( _("Preference file, %s, could not be written. Contact your system administrator to resolve this issue.") , $filename . '.tmp') ); exit; } @@ -226,7 +226,7 @@ logout_error( sprintf( _("Signature file, %s, could not be opened. Contact your system administrator to resolve this issue."), $filename . '.tmp') ); exit; } - if ( @fwrite($file, $value) === FALSE ) { + if ( sq_fwrite($file, $value) === FALSE ) { logout_error( sprintf( _("Signature file, %s, could not be written. Contact your system administrator to resolve this issue.") , $filename . '.tmp')); exit; } Index: strings.php =================================================================== RCS file: /cvsroot/squirrelmail/squirrelmail/functions/strings.php,v retrieving revision 1.184.2.14 retrieving revision 1.184.2.15 diff -u -w -r1.184.2.14 -r1.184.2.15 --- strings.php 3 Mar 2004 04:38:31 -0000 1.184.2.14 +++ strings.php 15 Mar 2004 10:20:14 -0000 1.184.2.15 @@ -487,5 +487,20 @@ print '</pre>'; } +/** + * version of fwrite which checks for failure + */ +function sq_fwrite($fp, $string) { + // write to file + $count = @fwrite($fp,$string); + // the number of bytes written should be the length of the string + if($count != strlen($string)) { + return FALSE; + } + + return $count; +} + + $PHP_SELF = php_self(); ?> |