From 62543788306c6a0c3190eb146de9d7a6cfeec4fd Mon Sep 17 00:00:00 2001 From: Ilia Alshanetsky Date: Wed, 13 Jan 2010 13:44:58 +0000 Subject: [PATCH] Fixed bug #50732 (exec() adds single byte twice to $output array). --- NEWS | 1 + ext/standard/exec.c | 4 +-- .../tests/general_functions/bug49847.phpt | 36 +++++++++++++++++++ .../tests/general_functions/bug50732.phpt | 36 +++++++++++++++++++ 4 files changed, 75 insertions(+), 2 deletions(-) create mode 100644 ext/standard/tests/general_functions/bug49847.phpt create mode 100644 ext/standard/tests/general_functions/bug50732.phpt diff --git a/NEWS b/NEWS index 1e40ba8454..6628f050f5 100644 --- a/NEWS +++ b/NEWS @@ -11,6 +11,7 @@ PHP NEWS (Ilia) - Added stream_resolve_include_path(). (Mikko) +- 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). diff --git a/ext/standard/exec.c b/ext/standard/exec.c index f97a79bd76..5850026e17 100644 --- a/ext/standard/exec.c +++ b/ext/standard/exec.c @@ -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 index 0000000000..637abd24ea --- /dev/null +++ b/ext/standard/tests/general_functions/bug49847.phpt @@ -0,0 +1,36 @@ +--TEST-- +Bug #49847 (exec() fails on lines larger then 4095 bytes) +--FILE-- + +--EXPECT-- +array(1) { + [0]=> + string(4098) " 1" +} +--TEST-- +Bug #49847 (exec() fails on lines larger then 4095 bytes) +--FILE-- + +--EXPECT-- +array(1) { + [0]=> + string(4098) " 1" +} +--TEST-- +Bug #49847 (exec() fails on lines larger then 4095 bytes) +--FILE-- + +--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 index 0000000000..e036b47ed6 --- /dev/null +++ b/ext/standard/tests/general_functions/bug50732.phpt @@ -0,0 +1,36 @@ +--TEST-- +Bug #50732 (exec() adds single byte twice to $output array) +--FILE-- + +--EXPECT-- +array(1) { + [0]=> + string(1) "x" +} +--TEST-- +Bug #50732 (exec() adds single byte twice to $output array) +--FILE-- + +--EXPECT-- +array(1) { + [0]=> + string(1) "x" +} +--TEST-- +Bug #50732 (exec() adds single byte twice to $output array) +--FILE-- + +--EXPECT-- +array(1) { + [0]=> + string(1) "x" +} -- 2.40.0