-
Notifications
You must be signed in to change notification settings - Fork 7.9k
throw on null bytes / resolve GH-13952 #18320
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from 5 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
c1b07f4
throw on null bytes / resolve GH-13952
divinity76 6d426fb
forgot about PDO::ERRMODE_SILENT
divinity76 0d4f551
stray comment
divinity76 097db31
wasn't supposed to be commited
divinity76 3f31cae
git problems sorry
divinity76 18b9e18
whitespace fixes / pr feedback
divinity76 c419245
whitespace...
divinity76 5506b75
fsck whitespace
divinity76 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
--TEST-- | ||
GH-13952 (sqlite PDO::quote handles null bytes correctly) | ||
--EXTENSIONS-- | ||
pdo | ||
pdo_sqlite | ||
--FILE-- | ||
<?php | ||
|
||
$modes = [ | ||
'exception' => PDO::ERRMODE_EXCEPTION, | ||
'warning' => PDO::ERRMODE_WARNING, | ||
'silent' => PDO::ERRMODE_SILENT, | ||
]; | ||
|
||
$test_cases = [ | ||
"", | ||
"x", | ||
"\x00", | ||
"a\x00b", | ||
"\x00\x00\x00", | ||
"foobar", | ||
"foo'''bar", | ||
"'foo'''bar'", | ||
"foo\x00bar", | ||
"'foo'\x00'bar'", | ||
"foo\x00\x00\x00bar", | ||
"\x00foo\x00\x00\x00bar\x00", | ||
"\x00\x00\x00foo", | ||
"foo\x00\x00\x00", | ||
"\x80", // << invalid UTF-8 | ||
"\x00\x80\x00", // << invalid UTF-8 with null bytes | ||
]; | ||
|
||
foreach ($modes as $mode_name => $mode) { | ||
echo "Testing error mode: $mode_name\n"; | ||
$db = new PDO('sqlite::memory:', null, null, [PDO::ATTR_ERRMODE => $mode]); | ||
|
||
foreach ($test_cases as $test) { | ||
$contains_null = str_contains($test, "\x00"); | ||
|
||
if ($mode === PDO::ERRMODE_EXCEPTION && $contains_null) { | ||
set_error_handler(fn() => throw new PDOException(), E_WARNING); | ||
try { | ||
$db->quote($test); | ||
throw new LogicException("Expected exception not thrown."); | ||
} catch (PDOException) { | ||
// expected | ||
} finally { | ||
restore_error_handler(); | ||
} | ||
} else { | ||
set_error_handler(fn() => null, E_WARNING); | ||
$quoted = $db->quote($test); | ||
restore_error_handler(); | ||
|
||
if ($contains_null) { | ||
if ($quoted !== false) { | ||
throw new LogicException("Expected false, got: " . var_export($quoted, true)); | ||
} | ||
} else { | ||
if ($quoted === false) { | ||
throw new LogicException("Unexpected false from quote()."); | ||
} | ||
$fetched = $db->query("SELECT $quoted")->fetchColumn(); | ||
if ($fetched !== $test) { | ||
throw new LogicException("Data corrupted: expected " . var_export($test, true) . " got " . var_export($fetched, true)); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
echo "ok\n"; | ||
?> | ||
--EXPECT-- | ||
Testing error mode: exception | ||
Testing error mode: warning | ||
Testing error mode: silent | ||
ok |
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.