Skip to content

Commit

Permalink
Fix bug #79410 (system() swallows last chunk if it is exactly 4095 by…
Browse files Browse the repository at this point in the history
…tes without newline)

Closes phpGH-5292.
Christian Schneider authored and nikic committed Mar 25, 2020
1 parent 2e8db5d commit c0840fe
Showing 3 changed files with 21 additions and 0 deletions.
4 changes: 4 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
@@ -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)

7 changes: 7 additions & 0 deletions ext/standard/exec.c
Original file line number Diff line number Diff line change
@@ -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;
10 changes: 10 additions & 0 deletions ext/standard/tests/misc/bug79410.phpt
Original file line number Diff line number Diff line change
@@ -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)

0 comments on commit c0840fe

Please sign in to comment.