]> granicus.if.org Git - php/commitdiff
Fixed bug #22414 and added a test case for it.
authorIlia Alshanetsky <iliaa@php.net>
Tue, 25 Feb 2003 16:21:00 +0000 (16:21 +0000)
committerIlia Alshanetsky <iliaa@php.net>
Tue, 25 Feb 2003 16:21:00 +0000 (16:21 +0000)
ext/standard/exec.c
ext/standard/tests/file/bug22414.phpt [new file with mode: 0644]

index e38069ab728a37c7a69a990534da8cc0780ff6a2..a7d4078dd0506fc8a067dbfe80982adef40df2f5 100644 (file)
@@ -213,7 +213,7 @@ int php_Exec(int type, char *cmd, pval *array, pval *return_value TSRMLS_DC)
        } else {
                size_t b;
 
-               while ((b = fread(buf, buflen, 1, fp)) > 0) {
+               while((b = php_stream_read(stream, buf, EXEC_INPUT_BUF)) > 0) {
                        if (output) {
                                PHPWRITE(buf, b);
                        }
diff --git a/ext/standard/tests/file/bug22414.phpt b/ext/standard/tests/file/bug22414.phpt
new file mode 100644 (file)
index 0000000..c67ae2e
--- /dev/null
@@ -0,0 +1,37 @@
+--TEST--
+Bug #22414: passthru() does not read data correctly
+--SKIPIF--
+<?php
+       if (empty(@shell_exec("which cat")) {
+               dir('skip cat binary needed for this test is not avaliable');
+       }
+?>
+--POST--
+--GET--
+--FILE--
+<?php
+       $php = getenv('TEST_PHP_EXECUTABLE');
+       $pwd = realpath(dirname(__FILE__));
+       
+       /* Regular Data Test */
+       passthru($php . ' -r " echo \"HELLO\"; "');
+
+       echo "\n";
+
+       /* Binary Data Test */
+       @unlink($pwd . '/passthru_test');
+       
+       $cmd = $php . ' -r \' passthru("cat ' . $php . '"); \' > ' . $pwd . '/passthru_test';
+       exec($cmd);
+       
+       if (md5_file($php) == md5_file($pwd . '/passthru_test')) {
+               echo "Works\n";
+       } else {
+               echo "Does not work\n";
+       }
+       
+       @unlink($pwd . '/passthru_test');
+?>
+--EXPECT--
+HELLO
+Works