ext/mysqli: Fix memory leak and missing error handling in mysqli_poll.#21408
Open
devnexen wants to merge 3 commits intophp:PHP-8.4from
Open
ext/mysqli: Fix memory leak and missing error handling in mysqli_poll.#21408devnexen wants to merge 3 commits intophp:PHP-8.4from
devnexen wants to merge 3 commits intophp:PHP-8.4from
Conversation
In mysqlnd_zval_array_from_mysqlnd_array, dest_array was not released on the error path. Also the callers were not checking the return value. Found via static analysis, the error path is difficult to trigger in practice.
ext/mysqli/mysqli_nonapi.c
Outdated
| MYSQLI_RESOURCE *my_res; | ||
| mysqli_object *intern = Z_MYSQLI_P(elem); | ||
| if (!(my_res = (MYSQLI_RESOURCE *)intern->ptr)) { | ||
| zval_ptr_dtor(&dest_array); |
Member
There was a problem hiding this comment.
Should it be zval_ptr_dtor(&dest_array) or zval_ptr_dtor(dest_array)?
Member
Author
There was a problem hiding this comment.
The first, it is zval dest_array;.
Member
There was a problem hiding this comment.
Did you drop this change? Why can I not see it anymore?
Member
|
I'm pretty sure that this is an impossible scenario. Why not replace it with an assert? |
ndossche
reviewed
Mar 11, 2026
| return FAILURE; | ||
| } | ||
| my_res = (MYSQLI_RESOURCE *)intern->ptr; | ||
| ZEND_ASSERT(my_res); |
Member
There was a problem hiding this comment.
And because this is now an assertion, the function can only ever return SUCCESS, making the return value unnecessary.
Member
Author
There was a problem hiding this comment.
yes I realise those are only internal helpers not APIS ...
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
In mysqlnd_zval_array_from_mysqlnd_array, dest_array was not released on the error path. Also the callers were not checking the return value.
Found via static analysis, the error path is difficult to trigger in practice.