]> granicus.if.org Git - php/commitdiff
- merge: Fixed bug #50732 (exec() adds single byte twice to array).
authorPierre Joye <pajoye@php.net>
Wed, 3 Feb 2010 18:11:24 +0000 (18:11 +0000)
committerPierre Joye <pajoye@php.net>
Wed, 3 Feb 2010 18:11:24 +0000 (18:11 +0000)
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]

index f97a79bd76accfa2ecd55f07f141fec766f8958e..5850026e17e8db943a564e5abe0c2be23fbad13b 100644 (file)
@@ -121,7 +121,7 @@ PHPAPI int php_exec(int type, char *cmd, zval *array, zval *return_value TSRMLS_
 
        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)) {
@@ -157,7 +157,7 @@ PHPAPI int php_exec(int type, char *cmd, zval *array, zval *return_value TSRMLS_
                }
                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..637abd2
--- /dev/null
@@ -0,0 +1,36 @@
+--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"
+}
+--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"
+}
+--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..e036b47
--- /dev/null
@@ -0,0 +1,36 @@
+--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"
+}
+--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"
+}
+--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"
+}