Fix GH-22854: Guard against NULL handle dereference in mysqli property access - #23766
Open
prateekbhujel wants to merge 1 commit into
Open
prateekbhujel wants to merge 1 commit into
prateekbhujel wants to merge 1 commit into
Conversation
…erty access When a connection fails on a pre-allocated mysqli instance (e.g. via $mysqli->connect(...)), mysql->mysql is freed and set to NULL while the instance remains in MYSQLI_STATUS_INITIALIZED. Reading properties such as $mysqli->errno, $mysqli->error, or dumping the object via var_dump() accessed p = mysql->mysql without checking for NULL, triggering an assertion failure on debug builds and SIGSEGV on release builds. Similarly, statement and result property readers lacked NULL checks on the underlying C pointers. Guard against NULL pointers in MYSQLI_GET_MYSQL, MYSQLI_GET_RESULT, MYSQLI_GET_STMT, and related property accessors, throwing an Error in verbose access or returning FAILURE in quiet/debug mode.
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.
When a connection fails on a pre-allocated mysqli instance (such as calling $mysqli->connect(...) after instantiation), mysql->mysql is closed and set to NULL while the instance remains in MYSQLI_STATUS_INITIALIZED. Reading properties like $mysqli->errno or $mysqli->error, or inspecting the object with var_dump(), accessed mysql->mysql without checking for NULL, triggering an assertion failure on debug builds and a crash on release builds.
Similarly, statement and result property readers lacked NULL guards on the underlying pointers. This adds NULL checks across the property access macros and reader functions in mysqli_prop.c to safely throw an Error on verbose access or return FAILURE in quiet/debug mode.
Fixes #22854