Skip to content

Commit f29964e

Browse files
author
Ilia Alshanetsky
committed
Fixed bug #22414 and added a test case for it.
1 parent 400f466 commit f29964e

File tree

2 files changed

+38
-1
lines changed

2 files changed

+38
-1
lines changed

ext/standard/exec.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ int php_Exec(int type, char *cmd, pval *array, pval *return_value TSRMLS_DC)
213213
} else {
214214
size_t b;
215215

216-
while ((b = fread(buf, buflen, 1, fp)) > 0) {
216+
while((b = php_stream_read(stream, buf, EXEC_INPUT_BUF)) > 0) {
217217
if (output) {
218218
PHPWRITE(buf, b);
219219
}

ext/standard/tests/file/bug22414.phpt

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
--TEST--
2+
Bug #22414: passthru() does not read data correctly
3+
--SKIPIF--
4+
<?php
5+
if (empty(@shell_exec("which cat")) {
6+
dir('skip cat binary needed for this test is not avaliable');
7+
}
8+
?>
9+
--POST--
10+
--GET--
11+
--FILE--
12+
<?php
13+
$php = getenv('TEST_PHP_EXECUTABLE');
14+
$pwd = realpath(dirname(__FILE__));
15+
16+
/* Regular Data Test */
17+
passthru($php . ' -r " echo \"HELLO\"; "');
18+
19+
echo "\n";
20+
21+
/* Binary Data Test */
22+
@unlink($pwd . '/passthru_test');
23+
24+
$cmd = $php . ' -r \' passthru("cat ' . $php . '"); \' > ' . $pwd . '/passthru_test';
25+
exec($cmd);
26+
27+
if (md5_file($php) == md5_file($pwd . '/passthru_test')) {
28+
echo "Works\n";
29+
} else {
30+
echo "Does not work\n";
31+
}
32+
33+
@unlink($pwd . '/passthru_test');
34+
?>
35+
--EXPECT--
36+
HELLO
37+
Works

0 commit comments

Comments
 (0)