Skip to content

Move stack->next assignment within if (stack) check #10090

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 13, 2022

Conversation

nielsdos
Copy link
Member

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 shows the intent that it is valid to call the function with NULL. The assignment to stack->next was not in the initial version of the code. Fix it by moving the assignment inside the if's body.

Note: I'm not sure if this should go into master or into 8.1, I chose master for now. Technically it is a bugfix, but it also likely doesn't affect existing uses because otherwise there likely would've been a bug report somewhere.

Copy link
Member

@iluuu1994 iluuu1994 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you! There seem to be no calls to phpdbg_stack_free() with NULL (which would crash on any reasonable platform). Thus it might make sense to just assert that the value isn't NULL and remove the check from the if condition. master is fine, as this check is essentially just redundant.

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.
@nielsdos nielsdos force-pushed the phpdbg_cmd-stack-next branch from eef529e to b2a4df8 Compare December 13, 2022 07:31
@nielsdos
Copy link
Member Author

Thanks for your comment, I've changed it to your suggestion.

@iluuu1994 iluuu1994 merged commit 3ab18d4 into php:master Dec 13, 2022
@iluuu1994
Copy link
Member

Thanks 🙂

@nielsdos nielsdos deleted the phpdbg_cmd-stack-next branch March 19, 2023 15:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants