Make PDO connection construction single-shot#22874
Open
iliaal wants to merge 1 commit into
Open
Conversation
Constructing a PDO handle over an already constructed one re-ran connection setup; for a persistent connection the second pass freed the pemalloc'd dbh with efree() and corrupted the heap. Besides a plain second __construct(), the same sink was reachable by reentering during a uri: DSN stream open, by retrying a persistent construct that failed after swapping in the persistent handle, and by a subclass destructor reentering while a failed persistent connect() unwinds. Track construction with an is_constructing flag, set as soon as the handle exists for both __construct() and connect(), carried onto the persistent handle and cleared only on success; construction is rejected once the driver is attached or a construction is in progress. A construct that fails now leaves the handle unusable instead of allowing a retry.
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.
Constructing a PDO over an already constructed handle re-runs connection setup and, for a persistent connection, frees the pemalloc'd dbh with efree(), corrupting the heap. The same sink is also reachable by reentering __construct() from a uri: DSN stream wrapper or a failed connect()'s destructor, and by retrying a persistent construct that failed after swapping in the handle. This makes construction single-shot: an is_constructing flag (an ABI-neutral bit taken from _reserved_flags, sizeof(pdo_dbh_t) unchanged) is set as soon as the handle exists for both __construct() and connect(), and construction is rejected once the driver is attached or one is already in progress. Behavior change: a construct that fails now leaves the handle unusable instead of allowing a retry.