Skip to content

Instantly share code, notes, and snippets.

@cmb69
Created December 1, 2019 15:52
Show Gist options
  • Save cmb69/aa8296994e683fdb2e9d6fbce4fbebda to your computer and use it in GitHub Desktop.
Save cmb69/aa8296994e683fdb2e9d6fbce4fbebda to your computer and use it in GitHub Desktop.
PHP bug #78569
ext/standard/proc_open.c | 17 ++++++++++++++++-
1 file changed, 16 insertions(+), 1 deletion(-)
diff --git a/ext/standard/proc_open.c b/ext/standard/proc_open.c
index 612cdf0f88..cf42469ba7 100644
--- a/ext/standard/proc_open.c
+++ b/ext/standard/proc_open.c
@@ -438,6 +438,7 @@ PHP_FUNCTION(proc_open)
int suppress_errors = 0;
int bypass_shell = 0;
int blocking_pipes = 0;
+ int quote_shell_command = 0;
#endif
#if PHP_CAN_DO_PTS
php_file_descriptor_t dev_ptmx = -1; /* master */
@@ -478,6 +479,13 @@ PHP_FUNCTION(proc_open)
blocking_pipes = 1;
}
}
+
+ item = zend_hash_str_find(Z_ARRVAL_P(other_options), "quote_shell_command", sizeof("quote_shell_command") - 1);
+ if (item != NULL) {
+ if (Z_TYPE_P(item) == IS_TRUE || ((Z_TYPE_P(item) == IS_LONG) && Z_LVAL_P(item))) {
+ quote_shell_command = 1;
+ }
+ }
}
#endif
@@ -742,12 +750,19 @@ PHP_FUNCTION(proc_open)
len = (sizeof(COMSPEC_NT) + sizeof(" /c ") + tmp_len + 1);
+ if (quote_shell_command) {
+ len += 5;
+ }
cmdw2 = (wchar_t *)malloc(len * sizeof(wchar_t));
if (!cmdw2) {
php_error_docref(NULL, E_WARNING, "Command conversion failed");
goto exit_fail;
}
- ret = _snwprintf(cmdw2, len, L"%hs /c %s", COMSPEC_NT, cmdw);
+ if (quote_shell_command) {
+ ret = _snwprintf(cmdw2, len, L"%hs /s /c \"%s\"", COMSPEC_NT, cmdw);
+ } else {
+ ret = _snwprintf(cmdw2, len, L"%hs /c %s", COMSPEC_NT, cmdw);
+ }
if (-1 == ret) {
free(cmdw2);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment