From 690a3202fd3631fec08f332f309ddc7ebd1bf942 Mon Sep 17 00:00:00 2001 From: krakjoe Date: Tue, 19 Nov 2013 19:10:09 +0000 Subject: [PATCH] escaped strings --- phpdbg_cmd.c | 35 +++++++++++++++++++++++------------ 1 file changed, 23 insertions(+), 12 deletions(-) diff --git a/phpdbg_cmd.c b/phpdbg_cmd.c index b03aecc246..06a32bb214 100644 --- a/phpdbg_cmd.c +++ b/phpdbg_cmd.c @@ -118,29 +118,31 @@ void phpdbg_clear_param(phpdbg_param_t *param TSRMLS_DC) /* {{{ */ } /* }}} */ -static inline phpdbg_input_t** phpdbg_read_argv(char *buffer, int *count TSRMLS_DC) /* {{{ */ +static inline phpdbg_input_t** phpdbg_read_argv(char *buffer, int *argc TSRMLS_DC) /* {{{ */ { char *p, *s; + char b[PHPDBG_MAX_CMD]; + int l=0; enum states { IN_BETWEEN, IN_WORD, IN_STRING } state = IN_BETWEEN; - phpdbg_input_t **inputs; + phpdbg_input_t **argv = NULL; + + argv = (phpdbg_input_t**) emalloc(sizeof(phpdbg_input_t**)); + (*argc) = 0; - (*count) = 0; - inputs = (phpdbg_input_t**) emalloc( - sizeof(phpdbg_input_t*) * 1); - #define RESET_STATE() do {\ phpdbg_input_t *next = emalloc(sizeof(phpdbg_input_t));\ if (next) {\ - next->string = estrndup(\ - s, ((p-1) - s)+1);\ - inputs[(*count)++] = next;\ + b[l]=0;\ + next->string = estrndup(b, l);\ + argv[(*argc)++] = next;\ + l=0;\ }\ state = IN_BETWEEN;\ -} while(0); +} while(0) for (p = buffer; *p != '\0'; p++) { int c = (unsigned char) *p; @@ -156,17 +158,26 @@ static inline phpdbg_input_t** phpdbg_read_argv(char *buffer, int *count TSRMLS_ } state = IN_WORD; s = p; + b[l++]=c; continue; case IN_STRING: - if (c == '"') { + if ((c == '"')) { + if (buffer[(p - buffer)-1] == '\\') { + b[l-1]=c; + continue; + } RESET_STATE(); + } else { + b[l++]=c; } continue; case IN_WORD: if (isspace(c)) { RESET_STATE(); + } else { + b[l++]=c; } continue; } @@ -182,7 +193,7 @@ static inline phpdbg_input_t** phpdbg_read_argv(char *buffer, int *count TSRMLS_ break; } - return inputs; + return argv; } /* }}} */ phpdbg_input_t* phpdbg_read_input(TSRMLS_D) /* {{{ */ -- 2.50.1