Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit ff6b309

Browse files
committed
Merge branch 'pull-request/1588' into PHP-7.0
* pull-request/1588: Fixed #69442 closing of fd incorrect when PTS enabled
2 parents b0ff9ee + e7f23e1 commit ff6b309

File tree

3 files changed

+55
-7
lines changed

3 files changed

+55
-7
lines changed

NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ PHP NEWS
1111
- Session:
1212
. Fixed bug #69582 (session not readable by root in CLI). (EvgeniySpinov)
1313

14+
- Standard:
15+
. Fixed bug #69442 (closing of fd incorrect when PTS enabled). (jaytaph)
16+
1417
19 Jan 2017 PHP 7.0.15
1518

1619
- Core:

ext/standard/proc_open.c

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -820,6 +820,12 @@ PHP_FUNCTION(proc_open)
820820
}
821821
#endif
822822

823+
#if PHP_CAN_DO_PTS
824+
if (dev_ptmx >= 0) {
825+
close(dev_ptmx);
826+
close(slave_pty);
827+
}
828+
#endif
823829
/* close those descriptors that we just opened for the parent stuff,
824830
* dup new descriptors into required descriptors and close the original
825831
* cruft */
@@ -835,13 +841,6 @@ PHP_FUNCTION(proc_open)
835841
close(descriptors[i].childend);
836842
}
837843

838-
#if PHP_CAN_DO_PTS
839-
if (dev_ptmx >= 0) {
840-
close(dev_ptmx);
841-
close(slave_pty);
842-
}
843-
#endif
844-
845844
if (cwd) {
846845
php_ignore_value(chdir(cwd));
847846
}

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)