Skip to content

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

Closed
wants to merge 1 commit into from

Conversation

cmb69
Copy link
Member

@cmb69 cmb69 commented Jul 18, 2022

The arguments 3 to 6 of the authorizer callback may be NULL[1], and
we have to properly deal with that. Instead of causing a segfault, we
deny authorization, which is still better than a crash, and apparently,
we cannot do better anyway.

[1] https://www.sqlite.org/c3ref/set_authorizer.html


Note that SQLITE_COPY is unused as of SQLite 3.6.10 (or earlier), but even for PHP-8.0 we require SQLite > 3.7.4, so there is no need to add that to php_sqlite3_authorizer(). I'll file a PR to remove that clause from master.

The arguments 3 to 6 of the authorizer callback may be `NULL`[1], and
we have to properly deal with that.  Instead of causing a segfault, we
deny authorization, which is still better than a crash, and apparently,
we cannot do better anyway.

[1] <https://www.sqlite.org/c3ref/set_authorizer.html>

try {
$st = $db->prepare('attach database :a AS "db2"');
$st->bindValue("a", ":memory:");
Copy link
Contributor

Choose a reason for hiding this comment

The 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 ATTACH DATABASE with value passed by param together with open_basedir?

Copy link
Member Author

Choose a reason for hiding this comment

The 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.

Copy link
Contributor

Choose a reason for hiding this comment

The 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

Copy link
Member Author

Choose a reason for hiding this comment

The 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.

@@ -737,7 +740,7 @@ static int authorizer(void *autharg, int access_type, const char *arg3, const ch
char *filename;
switch (access_type) {
case SQLITE_COPY: {
filename = make_filename_safe(arg4);
filename = make_filename_safe(arg4);
Copy link
Member

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 👍

@mvorisek
Copy link
Contributor

image

Is there any possibility I can get GH access to submit reviews and possibly update issues (edit, labels, ...)?

@cmb69
Copy link
Member Author

cmb69 commented Jul 19, 2022

If there are no objections, I'll merge this by the end of the week.

@cmb69 cmb69 closed this in 8ed21a8 Jul 27, 2022
@cmb69 cmb69 deleted the cmb/gh9032 branch July 27, 2022 11:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Sqlite ATTACH is crashing php when the filename is bind /w open_basedir set
3 participants