Skip to content

Commit 25d4392

Browse files
committed
Disable SQLITE_OPEN_URI feature when open_basedir is set
1 parent 85f5361 commit 25d4392

File tree

1 file changed

+5
-20
lines changed

1 file changed

+5
-20
lines changed

ext/pdo_sqlite/sqlite_driver.c

Lines changed: 5 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -735,27 +735,9 @@ static const struct pdo_dbh_methods sqlite_methods = {
735735
static char *make_filename_safe(const char *filename)
736736
{
737737
if (*filename && strncasecmp(filename, "file:", 5) == 0) {
738-
char *fullpath;
739-
if (strncasecmp(filename+5, "///", 3) == 0) {
740-
fullpath = expand_filepath(filename+7, NULL);
741-
} else if (strncasecmp(filename+5, "//localhost/", 12) == 0) {
742-
fullpath = expand_filepath(filename+16, NULL);
743-
} else if (strncasecmp(filename+5, "//", 2) == 0) {
744-
// authority error on sqlite3_open_v2
745-
return filename;
746-
} else {
747-
fullpath = expand_filepath(filename+5, NULL);
748-
}
749-
750-
if (!fullpath) {
751-
return NULL;
752-
}
753-
754-
if (php_check_open_basedir(fullpath)) {
755-
efree(fullpath);
738+
if (PG(open_basedir) && *PG(open_basedir)) {
756739
return NULL;
757740
}
758-
efree(fullpath);
759741
return estrdup(filename);
760742
}
761743
if (*filename && memcmp(filename, ":memory:", sizeof(":memory:"))) {
@@ -830,7 +812,10 @@ static int pdo_sqlite_handle_factory(pdo_dbh_t *dbh, zval *driver_options) /* {{
830812

831813
flags = pdo_attr_lval(driver_options, PDO_SQLITE_ATTR_OPEN_FLAGS, SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE);
832814

833-
i = sqlite3_open_v2(filename, &H->db, flags | SQLITE_OPEN_URI, NULL);
815+
if (!(PG(open_basedir) && *PG(open_basedir))) {
816+
flags |= SQLITE_OPEN_URI;
817+
}
818+
i = sqlite3_open_v2(filename, &H->db, flags, NULL);
834819

835820
efree(filename);
836821

0 commit comments

Comments
 (0)