]> granicus.if.org Git - php/commitdiff
Fix bug #79410 (system() swallows last chunk if it is exactly 4095 bytes without...
authorChristian Schneider <schneider@search.ch>
Tue, 24 Mar 2020 15:43:17 +0000 (16:43 +0100)
committerNikita Popov <nikita.ppv@gmail.com>
Wed, 25 Mar 2020 09:50:35 +0000 (10:50 +0100)
Closes GH-5292.

NEWS
ext/standard/exec.c
ext/standard/tests/misc/bug79410.phpt [new file with mode: 0644]

diff --git a/NEWS b/NEWS
index 51bd45a42867dff2819c4448f8b56a6dcd742823..ddcebd14fc0bb507fe3222e2c9d1170c652a3084 100644 (file)
--- 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)
 
index d914a1fd7262c5f863e5b582c7835f67f81cde04..7f8ce817e4a7abba90a3625d7d385cf3772220a0 100644 (file)
@@ -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 (file)
index 0000000..d14d12c
--- /dev/null
@@ -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)