summaryrefslogtreecommitdiff
path: root/sapi/phpdbg/phpdbg_prompt.c
diff options
context:
space:
mode:
authorBob Weinand <bobwei9@hotmail.com>2016-10-01 19:14:26 +0100
committerBob Weinand <bobwei9@hotmail.com>2016-10-01 19:14:26 +0100
commit3fe1010ceebe231afcee8aceae6782c18da23539 (patch)
tree06fc5009359d266419e274effedbce15b62ba5a8 /sapi/phpdbg/phpdbg_prompt.c
parent5f69c929ea845c2b1e0bfb978f6859d135590a80 (diff)
parent9d537951c5e4af5e453dd4d60e74dad039856b80 (diff)
downloadphp-git-3fe1010ceebe231afcee8aceae6782c18da23539.tar.gz
Merge branch 'PHP-7.0' into PHP-7.1
Diffstat (limited to 'sapi/phpdbg/phpdbg_prompt.c')
-rw-r--r--sapi/phpdbg/phpdbg_prompt.c106
1 files changed, 85 insertions, 21 deletions
diff --git a/sapi/phpdbg/phpdbg_prompt.c b/sapi/phpdbg/phpdbg_prompt.c
index c0ce007715..4ade755877 100644
--- a/sapi/phpdbg/phpdbg_prompt.c
+++ b/sapi/phpdbg/phpdbg_prompt.c
@@ -687,35 +687,84 @@ PHPDBG_COMMAND(run) /* {{{ */
}
}
- /* clean up from last execution */
- if (ex && (ZEND_CALL_INFO(ex) & ZEND_CALL_HAS_SYMBOL_TABLE)) {
- zend_hash_clean(ex->symbol_table);
- } else {
- zend_rebuild_symbol_table();
- }
- PHPDBG_G(handled_exception) = NULL;
-
- /* clean seek state */
- PHPDBG_G(flags) &= ~PHPDBG_SEEK_MASK;
- zend_hash_clean(&PHPDBG_G(seek));
-
- /* reset hit counters */
- phpdbg_reset_breakpoints();
-
if (param && param->type != EMPTY_PARAM && param->len != 0) {
char **argv = emalloc(5 * sizeof(char *));
+ char *end = param->str + param->len, *p = param->str;
int argc = 0;
int i;
- /* TODO allow proper escaping with \, "" and '' here */
- char *argv_str = strtok(param->str, " ");
- while (argv_str) {
+ while (*end == '\r' || *end == '\n') *(end--) = 0;
+
+ while (*p == ' ') p++;
+ while (*p) {
+ char sep = ' ';
+ char *buf = emalloc(end - p + 1), *q = buf;
+
+ if (*p == '<') {
+ /* use as STDIN */
+ do p++; while (*p == ' ');
+
+ if (*p == '\'' || *p == '"') {
+ sep = *(p++);
+ }
+ while (*p && *p != sep) {
+ if (*p == '\\' && (p[1] == sep || p[1] == '\\')) {
+ p++;
+ }
+ *(q++) = *(p++);
+ }
+ *(q++) = 0;
+ if (*p) {
+ do p++; while (*p == ' ');
+ }
+
+ if (*p) {
+ phpdbg_error("cmd", "", "Invalid run command, cannot put further arguments after stdin");
+ goto free_cmd;
+ }
+
+ PHPDBG_G(stdin_file) = fopen(buf, "r");
+ if (PHPDBG_G(stdin_file) == NULL) {
+ phpdbg_error("stdin", "path=\"%s\"", "Could not open '%s' for reading from stdin", buf);
+ goto free_cmd;
+ }
+ efree(buf);
+ break;
+ }
+
if (argc >= 4 && argc == (argc & -argc)) {
argv = erealloc(argv, (argc * 2 + 1) * sizeof(char *));
}
- argv[++argc] = argv_str;
- argv_str = strtok(0, " ");
- argv[argc] = estrdup(argv[argc]);
+
+ if (*p == '\'' || *p == '"') {
+ sep = *(p++);
+ }
+ if (*p == '\\' && (p[1] == '<' || p[1] == '\'' || p[1] == '"')) {
+ p++;
+ }
+ while (*p && *p != sep) {
+ if (*p == '\\' && (p[1] == sep || p[1] == '\\')) {
+ p++;
+ }
+ *(q++) = *(p++);
+ }
+ if (!*p && sep != ' ') {
+ phpdbg_error("cmd", "", "Invalid run command, unterminated escape sequence");
+free_cmd:
+ efree(buf);
+ for (i = 0; i < argc; i++) {
+ efree(argv[i]);
+ }
+ efree(argv);
+ return SUCCESS;
+ }
+
+ *(q++) = 0;
+ argv[++argc] = erealloc(buf, q - buf);
+
+ if (*p) {
+ do p++; while (*p == ' ');
+ }
}
argv[0] = SG(request_info).argv[0];
for (i = SG(request_info).argc; --i;) {
@@ -728,6 +777,21 @@ PHPDBG_COMMAND(run) /* {{{ */
php_build_argv(NULL, &PG(http_globals)[TRACK_VARS_SERVER]);
}
+ /* clean up from last execution */
+ if (ex && (ZEND_CALL_INFO(ex) & ZEND_CALL_HAS_SYMBOL_TABLE)) {
+ zend_hash_clean(ex->symbol_table);
+ } else {
+ zend_rebuild_symbol_table();
+ }
+ PHPDBG_G(handled_exception) = NULL;
+
+ /* clean seek state */
+ PHPDBG_G(flags) &= ~PHPDBG_SEEK_MASK;
+ zend_hash_clean(&PHPDBG_G(seek));
+
+ /* reset hit counters */
+ phpdbg_reset_breakpoints();
+
zend_try {
PHPDBG_G(flags) ^= PHPDBG_IS_INTERACTIVE;
PHPDBG_G(flags) |= PHPDBG_IS_RUNNING;