From: Bob Weinand Date: Tue, 15 Apr 2014 15:52:46 +0000 (+0000) Subject: Fixed segfault when input == NULL X-Git-Tag: php-5.6.0beta2~1^2~37^2~8^2~6 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=0e8637441c10c1a028d9c4619d32bb8ce9cb3ce4;p=php Fixed segfault when input == NULL --- diff --git a/phpdbg_cmd.c b/phpdbg_cmd.c index cc597f13ee..c6818fea3f 100644 --- a/phpdbg_cmd.c +++ b/phpdbg_cmd.c @@ -516,21 +516,24 @@ PHPDBG_API void phpdbg_stack_free(phpdbg_param_t *stack) { /* {{{ */ PHPDBG_API void phpdbg_stack_push(phpdbg_param_t *stack, phpdbg_param_t *param) { phpdbg_param_t *next = calloc(1, sizeof(phpdbg_param_t)); - + if (!next) return; - + *(next) = *(param); + next->next = NULL; + if (stack->top == NULL) { stack->top = next; + next->top = NULL; stack->next = next; } else { stack->top->next = next; next->top = stack->top; stack->top = next; } - + stack->len++; } /* }}} */ diff --git a/phpdbg_prompt.c b/phpdbg_prompt.c index 9a9f45b8fa..86fc4d718e 100644 --- a/phpdbg_prompt.c +++ b/phpdbg_prompt.c @@ -1023,18 +1023,18 @@ int phpdbg_interactive(TSRMLS_D) /* {{{ */ char *why = NULL; char *input = NULL; phpdbg_param_t stack; - + PHPDBG_G(flags) |= PHPDBG_IS_INTERACTIVE; input = phpdbg_read_input(NULL TSRMLS_CC); - + if (input) { do { yyscan_t scanner; YY_BUFFER_STATE state; phpdbg_init_param(&stack, STACK_PARAM); - + if (yylex_init(&scanner)) { phpdbg_error( "could not initialize scanner"); @@ -1042,7 +1042,7 @@ int phpdbg_interactive(TSRMLS_D) /* {{{ */ } state = yy_scan_string(input, scanner); - + if (yyparse(&stack, scanner) <= 0) { switch (ret = phpdbg_stack_execute(&stack, &why TSRMLS_CC)) { case FAILURE: @@ -1053,7 +1053,7 @@ int phpdbg_interactive(TSRMLS_D) /* {{{ */ } } } - + if (why) { free(why); why = NULL; @@ -1099,14 +1099,13 @@ last: out: if (input) { + phpdbg_stack_free(&stack); phpdbg_destroy_input(&input TSRMLS_CC); } if (why) { free(why); } - - phpdbg_stack_free(&stack); if (EG(in_execution)) { phpdbg_restore_frame(TSRMLS_C);