From 3c4b7cd2d61a77f62c7da3a2b09588e11bc84709 Mon Sep 17 00:00:00 2001 From: Christian Schneider Date: Tue, 24 Mar 2020 16:43:17 +0100 Subject: [PATCH 1/3] Fix Bug #79410 (system() swallows last chunk if it is exactly 4095 bytes without newline) and add test for it --- ext/standard/exec.c | 7 +++++++ ext/standard/tests/bug79410.phpt | 10 ++++++++++ 2 files changed, 17 insertions(+) create mode 100644 ext/standard/tests/bug79410.phpt diff --git a/ext/standard/exec.c b/ext/standard/exec.c index cdf983787b54..bdb090adc204 100644 --- a/ext/standard/exec.c +++ b/ext/standard/exec.c @@ -157,6 +157,13 @@ PHPAPI int php_exec(int type, char *cmd, zval *array, zval *return_value) b = buf; } if (bufl) { + /* output remaining data in buffer */ + if (type == 1) { + PHPWRITE(buf, bufl); + if (php_output_get_level() < 1) { + sapi_flush(); + } + } /* strip trailing whitespaces if we have not done so already */ if ((type == 2 && buf != b) || type != 2) { l = bufl; diff --git a/ext/standard/tests/bug79410.phpt b/ext/standard/tests/bug79410.phpt new file mode 100644 index 000000000000..64e68da66743 --- /dev/null +++ b/ext/standard/tests/bug79410.phpt @@ -0,0 +1,10 @@ +--TEST-- +Bug #79410 (system() swallows last chunk if it is exactly 4095 bytes without newline) +--FILE-- + +--EXPECT-- +int(4095) From 10bd1bf8adf5dc0cb9566896ee809246e294bd1e Mon Sep 17 00:00:00 2001 From: Christian Schneider Date: Tue, 24 Mar 2020 18:02:39 +0100 Subject: [PATCH 2/3] Add missing check if we already wrote everything --- ext/standard/exec.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ext/standard/exec.c b/ext/standard/exec.c index bdb090adc204..3b0e0a034f24 100644 --- a/ext/standard/exec.c +++ b/ext/standard/exec.c @@ -158,7 +158,7 @@ PHPAPI int php_exec(int type, char *cmd, zval *array, zval *return_value) } if (bufl) { /* output remaining data in buffer */ - if (type == 1) { + if (type == 1 && buf != b) { PHPWRITE(buf, bufl); if (php_output_get_level() < 1) { sapi_flush(); From e5cf2d9f3df1e485d90e933a437c4ad6251188a9 Mon Sep 17 00:00:00 2001 From: Christian Schneider Date: Wed, 25 Mar 2020 07:10:10 +0100 Subject: [PATCH 3/3] Update ext/standard/tests/bug79410.phpt Fixes test on Windows Co-Authored-By: Christoph M. Becker --- ext/standard/tests/bug79410.phpt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ext/standard/tests/bug79410.phpt b/ext/standard/tests/bug79410.phpt index 64e68da66743..d99d43506389 100644 --- a/ext/standard/tests/bug79410.phpt +++ b/ext/standard/tests/bug79410.phpt @@ -3,7 +3,7 @@ Bug #79410 (system() swallows last chunk if it is exactly 4095 bytes without new --FILE-- --EXPECT--