Check if proc_open/fopen actually succeeded before starting to write to it.
authorkink <kink@7612ce4b-ef26-0410-bec9-ea0150e637f0>
Mon, 24 Jan 2005 18:17:51 +0000 (18:17 +0000)
committerkink <kink@7612ce4b-ef26-0410-bec9-ea0150e637f0>
Mon, 24 Jan 2005 18:17:51 +0000 (18:17 +0000)
git-svn-id: https://svn.code.sf.net/p/squirrelmail/code/trunk/squirrelmail@8701 7612ce4b-ef26-0410-bec9-ea0150e637f0

plugins/squirrelspell/modules/check_me.mod

index 12f7e4ac20b869b69709ff841ef129ad96fedb80..d0594fd1d49e9670f8afa6a7e5e9021138e7cc71 100644 (file)
@@ -92,13 +92,18 @@ if( check_php_version ( 4, 3 ) ) {
        1 => array('pipe', 'w'),  // stdout is a pipe that the child will write to
        2 => array('pipe', 'w'), // stderr is a pipe that the child will write to
     );
        1 => array('pipe', 'w'),  // stdout is a pipe that the child will write to
        2 => array('pipe', 'w'), // stderr is a pipe that the child will write to
     );
-    $spell_proc=proc_open($sqspell_command, $descriptorspec, $pipes);
+    $spell_proc = @proc_open($sqspell_command, $descriptorspec, $pipes);
+    if ( ! is_resource ( $spell_proc ) ) {
+        error_box ( _("Could not run the spellchecker command (%s).",
+            htmlspecialchars($sqspell_command) ) , $color );
+    }
     fwrite($pipes[0], $sqspell_new_text);
     fclose($pipes[0]);
     $sqspell_output = array();
     fwrite($pipes[0], $sqspell_new_text);
     fclose($pipes[0]);
     $sqspell_output = array();
-    for($i=1; $i<=2; $i++){
-        while(!feof($pipes[$i]))
+    for($i=1; $i<=2; $i++) {
+        while(!feof($pipes[$i])) {
            array_push($sqspell_output, rtrim(fgetss($pipes[$i],999),"\n"));
            array_push($sqspell_output, rtrim(fgetss($pipes[$i],999),"\n"));
+        }
         fclose($pipes[$i]);
     }
     $sqspell_exitcode=proc_close($spell_proc);
         fclose($pipes[$i]);
     }
     $sqspell_exitcode=proc_close($spell_proc);
@@ -106,7 +111,11 @@ if( check_php_version ( 4, 3 ) ) {
     do {
       $floc = "$attachment_dir/" . md5($sqspell_new_text . microtime());
     } while (file_exists($floc));
     do {
       $floc = "$attachment_dir/" . md5($sqspell_new_text . microtime());
     } while (file_exists($floc));
-    $fp=fopen($floc, 'w');
+    $fp = @fopen($floc, 'w');
+    if ( ! is_resource ($fp) ) {
+        error_box ( _("Could not open temporary file '%s'.",
+            htmlspecialchars($floc) ) , $color );
+    }
     fwrite($fp, $sqspell_new_text);
     fclose($fp);
     exec("$sqspell_command < $floc 2>&1", $sqspell_output, $sqspell_exitcode);
     fwrite($fp, $sqspell_new_text);
     fclose($fp);
     exec("$sqspell_command < $floc 2>&1", $sqspell_output, $sqspell_exitcode);
@@ -435,4 +444,4 @@ if ($errors){
  * End:
  * vim: syntax=php et ts=4
  */
  * End:
  * vim: syntax=php et ts=4
  */
-?>
\ No newline at end of file
+?>