-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Fix GH-9032: SQLite3 authorizer crashes on NULL values #9040
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
--TEST-- | ||
SQLite3 authorizer crashes on NULL values | ||
--SKIPIF-- | ||
<?php | ||
if (!extension_loaded("pdo_sqlite")) die("skip pdo_sqlite extension not available"); | ||
?> | ||
--INI-- | ||
open_basedir=. | ||
--FILE-- | ||
<?php | ||
$db = new PDO("sqlite::memory:", null, null, [PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION]); | ||
|
||
$db->exec('attach database \':memory:\' AS "db1"'); | ||
var_dump($db->exec('create table db1.r (id int)')); | ||
|
||
try { | ||
$st = $db->prepare('attach database :a AS "db2"'); | ||
$st->execute([':a' => ':memory:']); | ||
var_dump($db->exec('create table db2.r (id int)')); | ||
} catch (PDOException $ex) { | ||
echo $ex->getMessage(), PHP_EOL; | ||
} | ||
?> | ||
--EXPECT-- | ||
int(0) | ||
SQLSTATE[HY000]: General error: 23 not authorized |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
--TEST-- | ||
SQLite3 authorizer crashes on NULL values | ||
--SKIPIF-- | ||
<?php | ||
if (!extension_loaded("sqlite3")) die("skip sqlite3 extension not available"); | ||
?> | ||
--INI-- | ||
open_basedir=. | ||
--FILE-- | ||
<?php | ||
$db = new SQLite3(":memory:"); | ||
$db->enableExceptions(true); | ||
|
||
$db->exec('attach database \':memory:\' AS "db1"'); | ||
var_dump($db->exec('create table db1.r (id int)')); | ||
|
||
try { | ||
$st = $db->prepare('attach database :a AS "db2"'); | ||
$st->bindValue("a", ":memory:"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I discovered this issue by using a database abstraction layer which bind strings as params. Is there any easy way to support the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No, I'm afraid that is just not possible. You would need to dynamically construct the SQL query instead. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 I see, it is also documented in https://www.php.net/manual/en/sqlite3.setauthorizer.php and it seems the only supported stage by Sqlite http://sqlite.org/c3ref/set_authorizer.html There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah, right, for ext/sqlite3 you could overwrite the authorizer callback; that is not (yet) supported for ext/pdo_sqlite, though. |
||
$st->execute(); | ||
var_dump($db->exec('create table db2.r (id int)')); | ||
} catch (Exception $ex) { | ||
echo $ex->getMessage(), PHP_EOL; | ||
} | ||
?> | ||
--EXPECT-- | ||
bool(true) | ||
Unable to prepare statement: 23, not authorized |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
glad you thought of it, kind of disturbed me when I saw it the other day 👍