]> granicus.if.org Git - php/commitdiff
Fixed bug #50732 (exec() adds single byte twice to $output array).
authorIlia Alshanetsky <iliaa@php.net>
Wed, 13 Jan 2010 13:44:58 +0000 (13:44 +0000)
committerIlia Alshanetsky <iliaa@php.net>
Wed, 13 Jan 2010 13:44:58 +0000 (13:44 +0000)
NEWS
ext/standard/exec.c
ext/standard/tests/general_functions/bug49847.phpt [new file with mode: 0644]
ext/standard/tests/general_functions/bug50732.phpt [new file with mode: 0644]

diff --git a/NEWS b/NEWS
index c5615f477258a7f090a8d11966b1cacb66b6791e..14fbf44e69ba88e7001aba002376c6f6a4c5059a 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -13,6 +13,7 @@ PHP                                                                        NEWS
 
 - Fixed build of mysqli with MySQL 5.5.0-m2. (Andrey)
 
+- Fixed bug #50732 (exec() adds single byte twice to $output array). (Ilia)
 - Fixed bug #50728 (All PDOExceptions hardcode 'code' property to 0). (Joey,
   Ilia)
 - Fixed bug #50680 (strtotime() does not support eighth ordinal number).
index 7fcae45bedf982e982e1573b0218cc99adc87a79..fdc8fffde4a0e4231afd277fb8fe2439ad94a6bd 100644 (file)
@@ -118,7 +118,7 @@ int php_exec(int type, char *cmd, zval *array, zval *return_value TSRMLS_DC)
 
        if (type != 3) {
                b = buf;
-               
+
                while (php_stream_get_line(stream, b, EXEC_INPUT_BUF, &bufl)) {
                        /* no new line found, let's read some more */
                        if (b[bufl - 1] != '\n' && !php_stream_eof(stream)) {
@@ -154,7 +154,7 @@ int php_exec(int type, char *cmd, zval *array, zval *return_value TSRMLS_DC)
                }
                if (bufl) {
                        /* strip trailing whitespaces if we have not done so already */ 
-                       if ((type == 2 && bufl && !l) || type != 2) {
+                       if ((type == 2 && buf != b) || type != 2) {
                                l = bufl;
                                while (l-- && isspace(((unsigned char *)buf)[l]));
                                if (l != (int)(bufl - 1)) {
diff --git a/ext/standard/tests/general_functions/bug49847.phpt b/ext/standard/tests/general_functions/bug49847.phpt
new file mode 100644 (file)
index 0000000..01ee161
--- /dev/null
@@ -0,0 +1,12 @@
+--TEST--
+Bug #49847 (exec() fails on lines larger then 4095 bytes)
+--FILE--
+<?php
+exec("printf %4098d 1", $output);
+var_dump($output);
+?>
+--EXPECT--
+array(1) {
+  [0]=>
+  string(4098) "                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 1"
+}
diff --git a/ext/standard/tests/general_functions/bug50732.phpt b/ext/standard/tests/general_functions/bug50732.phpt
new file mode 100644 (file)
index 0000000..ed8341d
--- /dev/null
@@ -0,0 +1,12 @@
+--TEST--
+Bug #50732 (exec() adds single byte twice to $output array)
+--FILE--
+<?php
+exec("echo x", $output);
+var_dump($output);
+?>
+--EXPECT--
+array(1) {
+  [0]=>
+  string(1) "x"
+}