Skip to content

Commit 568ed47

Browse files
committed
Merge branch 'PHP-8.2'
* PHP-8.2: Fix #81742: open_basedir bypass in SQLite3 by using file URI
2 parents e4ef394 + 8301803 commit 568ed47

File tree

2 files changed

+15
-8
lines changed

2 files changed

+15
-8
lines changed

ext/sqlite3/sqlite3.c

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2076,14 +2076,8 @@ static int php_sqlite3_authorizer(void *autharg, int action, const char *arg1, c
20762076
if (memcmp(arg1, ":memory:", sizeof(":memory:")) && *arg1) {
20772077
if (strncmp(arg1, "file:", 5) == 0) {
20782078
/* starts with "file:" */
2079-
if (!arg1[5]) {
2080-
return SQLITE_DENY;
2081-
}
2082-
if (php_check_open_basedir(arg1 + 5)) {
2083-
return SQLITE_DENY;
2084-
}
2085-
}
2086-
if (php_check_open_basedir(arg1)) {
2079+
return SQLITE_DENY;
2080+
} else if (php_check_open_basedir(arg1)) {
20872081
return SQLITE_DENY;
20882082
}
20892083
}

ext/sqlite3/tests/bug81742.phpt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
--TEST--
2+
Bug #81742 (open_basedir bypass in SQLite3 by using url encoded file)
3+
--EXTENSIONS--
4+
sqlite3
5+
--INI--
6+
open_basedir=.
7+
--FILE--
8+
<?php
9+
$db = new SQLite3(':memory:');
10+
$db->query("ATTACH 'file:..%2ffoo.php' as db2;");
11+
?>
12+
--EXPECTF--
13+
Warning: SQLite3::query(): not authorized in %s on line %d

0 commit comments

Comments
 (0)