Make PDO connection construction single-shot#191
Closed
iliaal wants to merge 1 commit into
Closed
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.
iliaal
force-pushed
the
fix/pdo-guard-reconstruct
branch
from
July 23, 2026 14:35
5806ad2 to
980028e
Compare
Owner
Author
|
Promoted upstream: php#22874 |
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. The fix marks construction in progress with an ABI-neutral reserved bit (sizeof unchanged) and rejects reconstruction for both __construct() and connect(). A construct that fails now throws on retry rather than corrupting.