Skip to content

Commit c0840fe

Browse files
Christian Schneidernikic
Christian Schneider
authored andcommitted
Fix bug #79410 (system() swallows last chunk if it is exactly 4095 bytes without newline)
Closes GH-5292.
1 parent 2e8db5d commit c0840fe

File tree

3 files changed

+21
-0
lines changed

3 files changed

+21
-0
lines changed

NEWS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@ PHP NEWS
2424
. Fixed bug #79393 (Null coalescing operator failing with SplFixedArray).
2525
(cmb)
2626

27+
- Standard:
28+
. Fixed bug #79410 (system() swallows last chunk if it is exactly 4095 bytes
29+
without newline). (Christian Schneider)
30+
2731
- Zip:
2832
. Fixed Bug #79296 (ZipArchive::open fails on empty file). (Remi)
2933

ext/standard/exec.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,13 @@ PHPAPI int php_exec(int type, char *cmd, zval *array, zval *return_value)
162162
b = buf;
163163
}
164164
if (bufl) {
165+
/* output remaining data in buffer */
166+
if (type == 1 && buf != b) {
167+
PHPWRITE(buf, bufl);
168+
if (php_output_get_level() < 1) {
169+
sapi_flush();
170+
}
171+
}
165172
/* strip trailing whitespaces if we have not done so already */
166173
if ((type == 2 && buf != b) || type != 2) {
167174
l = bufl;

ext/standard/tests/misc/bug79410.phpt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
--TEST--
2+
Bug #79410 (system() swallows last chunk if it is exactly 4095 bytes without newline)
3+
--FILE--
4+
<?php
5+
ob_start();
6+
system(getenv('TEST_PHP_EXECUTABLE') . ' -n -r "echo str_repeat(\".\", 4095);"');
7+
var_dump(strlen(ob_get_clean()));
8+
?>
9+
--EXPECT--
10+
int(4095)

0 commit comments

Comments
 (0)