Skip to content

Commit 0ca4358

Browse files
committed
Merge branch 'PHP-7.1'
* PHP-7.1: Fixed #69442 closing of fd incorrect when PTS enabled
2 parents 969622c + 69b1526 commit 0ca4358

File tree

3 files changed

+53
-7
lines changed

3 files changed

+53
-7
lines changed

NEWS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ PHP NEWS
9999
. Add subject to mail log. (tomsommer)
100100
. Fixed bug #31875 (get_defined_functions additional param to exclude
101101
disabled functions). (willianveiga)
102+
. Fixed bug #69442 (closing of fd incorrect when PTS enabled). (jaytaph)
102103

103104
- XML:
104105
. Moved utf8_encode() and utf8_decode() to the Standard extension. (Andrea)

ext/standard/proc_open.c

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -811,6 +811,12 @@ PHP_FUNCTION(proc_open)
811811
}
812812
#endif
813813

814+
#if PHP_CAN_DO_PTS
815+
if (dev_ptmx >= 0) {
816+
close(dev_ptmx);
817+
close(slave_pty);
818+
}
819+
#endif
814820
/* close those descriptors that we just opened for the parent stuff,
815821
* dup new descriptors into required descriptors and close the original
816822
* cruft */
@@ -826,13 +832,6 @@ PHP_FUNCTION(proc_open)
826832
close(descriptors[i].childend);
827833
}
828834

829-
#if PHP_CAN_DO_PTS
830-
if (dev_ptmx >= 0) {
831-
close(dev_ptmx);
832-
close(slave_pty);
833-
}
834-
#endif
835-
836835
if (cwd) {
837836
php_ignore_value(chdir(cwd));
838837
}

ext/standard/tests/file/bug69442.phpt

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
--TEST--
2+
proc_open with PTY closes incorrect file descriptor
3+
--SKIPIF--
4+
<?php
5+
6+
$code = <<< 'EOC'
7+
<?php
8+
$descriptors = array(array("pty"), array("pty"), array("pty"), array("pipe", "w"));
9+
$pipes = array();
10+
$process = proc_open('echo "foo";', $descriptors, $pipes);
11+
EOC;
12+
13+
$tmpFile = tempnam(sys_get_temp_dir(), "bug69442");
14+
file_put_contents($tmpFile, $code);
15+
16+
exec($_SERVER['TEST_PHP_EXECUTABLE']." ".$tmpFile." 2>&1", $output);
17+
$output = join("\n", $output);
18+
unlink($tmpFile);
19+
20+
if (strstr($output, "pty pseudo terminal not supported on this system") !== false) {
21+
die("skip PTY pseudo terminals are not supported");
22+
}
23+
--FILE--
24+
<?php
25+
$cmd = '(echo "foo" ; exit 42;) 3>/dev/null; code=$?; echo $code >&3; exit $code';
26+
$descriptors = array(array("pty"), array("pty"), array("pty"), array("pipe", "w"));
27+
$pipes = array();
28+
29+
$process = proc_open($cmd, $descriptors, $pipes);
30+
31+
foreach ($pipes as $type => $pipe) {
32+
$data = fread($pipe, 999);
33+
echo 'type ' . $type . ' ';
34+
var_dump($data);
35+
fclose($pipe);
36+
}
37+
proc_close($process);
38+
--EXPECT--
39+
type 0 string(5) "foo
40+
"
41+
type 1 string(0) ""
42+
type 2 string(0) ""
43+
type 3 string(3) "42
44+
"
45+
46+

0 commit comments

Comments
 (0)