From 3ab18d4d1464477e470900ddd372b79cc3136490 Mon Sep 17 00:00:00 2001 From: Niels <7771979+nielsdos@users.noreply.github.com> Date: Tue, 13 Dec 2022 13:16:52 +0100 Subject: [PATCH] Change if (stack) check to an assertion (#10090) 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 7e6a87fcc89..f5701384d3a 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; } /* }}} */ /* {{{ */