From d1ff787b46885d493e28314e516c45f78e573265 Mon Sep 17 00:00:00 2001 From: Patrick Dowell Date: Wed, 18 Dec 2013 09:26:38 -0800 Subject: [PATCH] fix to allow proc_open() to accept php://stdin as stdin I added some code to the openFile function in runtime/ext/ext_process.cpp that accounts for the case when the user calls proc_open() using php://stdin as stdin for the process spawned. Reviewed By: @ptarjan Differential Revision: D1094713 --- hphp/runtime/ext/ext_process.cpp | 18 +++++++++++----- hphp/test/slow/ext_process/proc_open.php | 26 ++++++++++++++++++++++++ hphp/test/slow/ext_process/proc_open.php.expectf | 7 +++++++ hphp/test/slow/ext_process/proc_open.php.in | 3 +++ hphp/test/slow/ext_process/test_proc_open.sh | 4 ++++ hphp/test/slow/ext_process/test_proc_open.txt | 1 + 6 files changed, 54 insertions(+), 5 deletions(-) create mode 100644 hphp/test/slow/ext_process/proc_open.php create mode 100644 hphp/test/slow/ext_process/proc_open.php.expectf create mode 100644 hphp/test/slow/ext_process/proc_open.php.in create mode 100755 hphp/test/slow/ext_process/test_proc_open.sh create mode 100644 hphp/test/slow/ext_process/test_proc_open.txt diff --git a/hphp/runtime/ext/ext_process.cpp b/hphp/runtime/ext/ext_process.cpp index e7d4d8e9c2c..66b3a6af5de 100644 --- a/hphp/runtime/ext/ext_process.cpp +++ b/hphp/runtime/ext/ext_process.cpp @@ -627,15 +627,23 @@ public: bool openFile(const String& zfile, const String& zmode) { mode = DESC_FILE; - /* try a wrapper */ - FILE *file = fopen(zfile.c_str(), zmode.c_str()); - if (!file) { + /* try a wrapper */ + Variant vfile = f_fopen(zfile.c_str(), zmode.c_str()); + if (!vfile.isResource()) { raise_warning("Unable to open specified file: %s (mode %s)", zfile.data(), zmode.data()); return false; + } else { + File *file = vfile.toResource().getTyped(); + file->flush(); + childend = dup(file->fd()); + if (childend < 0) { + raise_warning("unable to dup File-Handle for descriptor %d - %s", + index, folly::errnoStr(errno).c_str()); + return false; + } + return true; } - childend = fileno(file); - return true; } void dupChild() { diff --git a/hphp/test/slow/ext_process/proc_open.php b/hphp/test/slow/ext_process/proc_open.php new file mode 100644 index 00000000000..8328cc0e519 --- /dev/null +++ b/hphp/test/slow/ext_process/proc_open.php @@ -0,0 +1,26 @@ +