Commit 49a85e33439 for php
commit 49a85e3343969b682de98c7bdf5355a3c6194953
Author: lazerg <lazerg2@gmail.com>
Date: Sat Dec 5 13:15:13 2026 +0500
Fix GH-26084: OOB read in sqlite3 authorizer for short ATTACH names (#26088)
With open_basedir set, the authorizer compares ATTACH filenames against
":memory:" using memcmp() over nine bytes. This reads past the allocation
for names shorter than eight characters. Use strcmp() instead, as the
reporter suggested.
The regression test exposes the out-of-bounds read under ASAN when SQLite
is built without lookaside; otherwise the name lives in a larger slot.
Co-authored-by: br1p4v3s1 <193321153+br1p4v3s1@users.noreply.github.com>
Closes #26088
diff --git a/NEWS b/NEWS
index 380b4eb6a74..b1840b1f3f2 100644
--- a/NEWS
+++ b/NEWS
@@ -51,6 +51,10 @@ PHP NEWS
. Fixed upload progress cleanup creating a session and sending a session
cookie when no file was uploaded. (Ho Hoang Phu)
+- SQLite3:
+ . Fixed bug GH-26084 (Out-of-bounds read in the authorizer for short ATTACH
+ names with open_basedir). (lazerg, br1p4v3s1)
+
- Standard:
. Fixed bug GH-25959 ("consumed" stream filter loses or repeats data).
(Artem Ukrainskiy)
diff --git a/ext/sqlite3/sqlite3.c b/ext/sqlite3/sqlite3.c
index 4d2c74891c9..2d1d61fa69a 100644
--- a/ext/sqlite3/sqlite3.c
+++ b/ext/sqlite3/sqlite3.c
@@ -2144,7 +2144,7 @@ static int php_sqlite3_authorizer(void *autharg, int action, const char *arg1, c
if (!arg1) {
return SQLITE_DENY;
}
- if (memcmp(arg1, ":memory:", sizeof(":memory:")) && *arg1) {
+ if (strcmp(arg1, ":memory:") != 0 && *arg1) {
if (strncmp(arg1, "file:", 5) == 0) {
/* starts with "file:" */
return SQLITE_DENY;
diff --git a/ext/sqlite3/tests/gh26084.phpt b/ext/sqlite3/tests/gh26084.phpt
new file mode 100644
index 00000000000..299f33211ac
--- /dev/null
+++ b/ext/sqlite3/tests/gh26084.phpt
@@ -0,0 +1,15 @@
+--TEST--
+GH-26084 (Out-of-bounds read in php_sqlite3_authorizer for short ATTACH names with open_basedir)
+--EXTENSIONS--
+sqlite3
+--INI--
+open_basedir=.
+--FILE--
+<?php
+$db = new SQLite3(":memory:");
+var_dump($db->exec("ATTACH DATABASE '' AS aux"));
+var_dump($db->exec("CREATE TABLE aux.t (id int)"));
+?>
+--EXPECT--
+bool(true)
+bool(true)