From b2a4df84ed7ba6942ee7b2f613ab4f16b827ed07 Mon Sep 17 00:00:00 2001 From: Niels Dossche <7771979+nielsdos@users.noreply.github.com> Date: Tue, 13 Dec 2022 08:29:58 +0100 Subject: [PATCH] Change if (stack) check to an assertion The code checks if stack is a NULL pointer. Below that if the stack->next pointer is updated unconditionally. Therefore a call with a NULL pointer will crash, even though the if (stack) check seems to show the intent that it is valid to call the function with NULL. The function is not meant to be called with NULL, so just ZEND_ASSERT instead. --- sapi/phpdbg/phpdbg_cmd.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/sapi/phpdbg/phpdbg_cmd.c b/sapi/phpdbg/phpdbg_cmd.c index 7e6a87fcc89e3..f5701384d3a20 100644 --- a/sapi/phpdbg/phpdbg_cmd.c +++ b/sapi/phpdbg/phpdbg_cmd.c @@ -371,7 +371,9 @@ PHPDBG_API void phpdbg_param_debug(const phpdbg_param_t *param, const char *msg) /* {{{ */ PHPDBG_API void phpdbg_stack_free(phpdbg_param_t *stack) { - if (stack && stack->next) { + ZEND_ASSERT(stack != NULL); + + if (stack->next) { phpdbg_param_t *remove = stack->next; while (remove) { @@ -422,10 +424,9 @@ PHPDBG_API void phpdbg_stack_free(phpdbg_param_t *stack) { remove = next; else break; } - } - - stack->next = NULL; + stack->next = NULL; + } } /* }}} */ /* {{{ */