summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoe Watkins <krakjoe@php.net>2017-01-06 06:57:35 +0000
committerJoe Watkins <krakjoe@php.net>2017-01-06 06:58:56 +0000
commite86d355c4c828be63fbccb24ba60cb08310408e8 (patch)
tree5d1560bf5e60d7af229eccba868d438daa7a5c49
parent811dfaa57b914630e1805c96f3fed83ecc97cc45 (diff)
parentff6b309c6f4c26ffedd5fc9e4cd021b7300617a3 (diff)
downloadphp-git-e86d355c4c828be63fbccb24ba60cb08310408e8.tar.gz
Merge branch 'PHP-7.0' into PHP-7.1
* PHP-7.0: Fixed #69442 closing of fd incorrect when PTS enabled
-rw-r--r--NEWS3
-rw-r--r--ext/standard/proc_open.c13
-rw-r--r--ext/standard/tests/file/bug69442.phpt46
3 files changed, 55 insertions, 7 deletions
diff --git a/NEWS b/NEWS
index 61ee9502d8..137d9a4191 100644
--- a/NEWS
+++ b/NEWS
@@ -11,6 +11,9 @@ PHP NEWS
- Session:
. Fixed bug #69582 (session not readable by root in CLI). (EvgeniySpinov)
+- Standard:
+ . Fixed bug #69442 (closing of fd incorrect when PTS enabled). (jaytaph)
+
19 Jan 2017, PHP 7.1.1
- Core:
diff --git a/ext/standard/proc_open.c b/ext/standard/proc_open.c
index b0e448b2cf..de1304d48e 100644
--- a/ext/standard/proc_open.c
+++ b/ext/standard/proc_open.c
@@ -865,6 +865,12 @@ PHP_FUNCTION(proc_open)
}
#endif
+#if PHP_CAN_DO_PTS
+ if (dev_ptmx >= 0) {
+ close(dev_ptmx);
+ close(slave_pty);
+ }
+#endif
/* close those descriptors that we just opened for the parent stuff,
* dup new descriptors into required descriptors and close the original
* cruft */
@@ -880,13 +886,6 @@ PHP_FUNCTION(proc_open)
close(descriptors[i].childend);
}
-#if PHP_CAN_DO_PTS
- if (dev_ptmx >= 0) {
- close(dev_ptmx);
- close(slave_pty);
- }
-#endif
-
if (cwd) {
php_ignore_value(chdir(cwd));
}
diff --git a/ext/standard/tests/file/bug69442.phpt b/ext/standard/tests/file/bug69442.phpt
new file mode 100644
index 0000000000..e5255acb37
--- /dev/null
+++ b/ext/standard/tests/file/bug69442.phpt
@@ -0,0 +1,46 @@
+--TEST--
+proc_open with PTY closes incorrect file descriptor
+--SKIPIF--
+<?php
+
+$code = <<< 'EOC'
+ <?php
+ $descriptors = array(array("pty"), array("pty"), array("pty"), array("pipe", "w"));
+ $pipes = array();
+ $process = proc_open('echo "foo";', $descriptors, $pipes);
+EOC;
+
+ $tmpFile = tempnam(sys_get_temp_dir(), "bug69442");
+ file_put_contents($tmpFile, $code);
+
+ exec($_SERVER['TEST_PHP_EXECUTABLE']." ".$tmpFile." 2>&1", $output);
+ $output = join("\n", $output);
+ unlink($tmpFile);
+
+ if (strstr($output, "pty pseudo terminal not supported on this system") !== false) {
+ die("skip PTY pseudo terminals are not supported");
+ }
+--FILE--
+<?php
+$cmd = '(echo "foo" ; exit 42;) 3>/dev/null; code=$?; echo $code >&3; exit $code';
+$descriptors = array(array("pty"), array("pty"), array("pty"), array("pipe", "w"));
+$pipes = array();
+
+$process = proc_open($cmd, $descriptors, $pipes);
+
+foreach ($pipes as $type => $pipe) {
+ $data = fread($pipe, 999);
+ echo 'type ' . $type . ' ';
+ var_dump($data);
+ fclose($pipe);
+}
+proc_close($process);
+--EXPECT--
+type 0 string(5) "foo
+"
+type 1 string(0) ""
+type 2 string(0) ""
+type 3 string(3) "42
+"
+
+