summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Schneider <schneider@search.ch>2020-03-24 16:43:17 +0100
committerNikita Popov <nikita.ppv@gmail.com>2020-03-25 10:50:35 +0100
commitc0840fec9c28bf0133391e4d0a9a4d8dbf4e9967 (patch)
tree0a0728ed74b426d3e905a905830303043b02407a
parent2e8db5d6be60325f79dc1b40b5163b47d8ef65d5 (diff)
downloadphp-git-c0840fec9c28bf0133391e4d0a9a4d8dbf4e9967.tar.gz
Fix bug #79410 (system() swallows last chunk if it is exactly 4095 bytes without newline)
Closes GH-5292.
-rw-r--r--NEWS4
-rw-r--r--ext/standard/exec.c7
-rw-r--r--ext/standard/tests/misc/bug79410.phpt10
3 files changed, 21 insertions, 0 deletions
diff --git a/NEWS b/NEWS
index 51bd45a428..ddcebd14fc 100644
--- a/NEWS
+++ b/NEWS
@@ -24,6 +24,10 @@ PHP NEWS
. Fixed bug #79393 (Null coalescing operator failing with SplFixedArray).
(cmb)
+- Standard:
+ . Fixed bug #79410 (system() swallows last chunk if it is exactly 4095 bytes
+ without newline). (Christian Schneider)
+
- Zip:
. Fixed Bug #79296 (ZipArchive::open fails on empty file). (Remi)
diff --git a/ext/standard/exec.c b/ext/standard/exec.c
index d914a1fd72..7f8ce817e4 100644
--- a/ext/standard/exec.c
+++ b/ext/standard/exec.c
@@ -162,6 +162,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 && buf != b) {
+ 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/misc/bug79410.phpt b/ext/standard/tests/misc/bug79410.phpt
new file mode 100644
index 0000000000..d14d12c406
--- /dev/null
+++ b/ext/standard/tests/misc/bug79410.phpt
@@ -0,0 +1,10 @@
+--TEST--
+Bug #79410 (system() swallows last chunk if it is exactly 4095 bytes without newline)
+--FILE--
+<?php
+ob_start();
+system(getenv('TEST_PHP_EXECUTABLE') . ' -n -r "echo str_repeat(\".\", 4095);"');
+var_dump(strlen(ob_get_clean()));
+?>
+--EXPECT--
+int(4095)