Skip to content

Fix GH-24490: pdo_pgsql prepare() hangs on a query containing a NUL byte - #24496

Closed
dev-null-undefined wants to merge 1 commit into
php:masterfrom
dev-null-undefined:gh24490
Closed

dev-null-undefined wants to merge 1 commit into
php:masterfrom
dev-null-undefined:gh24490

Conversation

@dev-null-undefined

Copy link
Copy Markdown

No rule in the scanner matches a NUL byte, so what re2c does with one is undefined. Before 5ccc56b it happened to skip one character. Now it returns a zero-length text token and pdo_parse_params() loops forever, or reads an uninitialized YYMARKER if the NUL is the first byte. Add a default rule so a NUL is skipped as one character of text again. This also gets rid of re2c's -Wundefined-control-flow warning for this scanner.

The regression is only on master (GH-24353). The new test hangs without the fix, and the ext/pdo_pgsql tests pass against PostgreSQL 18.6.

Fixes #24490

foreach ([true, false] as $emulate) {
$db->setAttribute(PDO::ATTR_EMULATE_PREPARES, $emulate);
$db->prepare("SELECT 'abc\0def'");
$db->prepare("\0SELECT 1");

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

can we add this case too here ?

+    try {
+        $db->prepare("SELECT '\0', ?, :p");
+    } catch (\Throwable $e) {
+        echo $e::class, ": ", $e->getMessage(), "\n";
+    }

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Done, thanks.

…L byte

No rule in the scanner matches a NUL byte, so what re2c does with one
is undefined. Before 5ccc56b it happened to skip one character. Now
it returns a zero-length text token and pdo_parse_params() loops
forever, or reads an uninitialized YYMARKER if the NUL is the first
byte. Add a default rule so a NUL is skipped as one character of text
again.
@devnexen devnexen closed this in b91ea88 Oct 22, 2026
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.

pdo_pgsql: prepare() hangs on a query containing a NUL byte

2 participants