Skip to content

Commit d3ad6e6

Browse files
author
Ilia Alshanetsky
committed
Do not perform safe_mode & open_basedir checks for memory-only databases.
1 parent f295772 commit d3ad6e6

File tree

1 file changed

+18
-12
lines changed

1 file changed

+18
-12
lines changed

ext/sqlite/sqlite.c

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -733,15 +733,19 @@ PHP_FUNCTION(sqlite_popen)
733733
return;
734734
}
735735

736-
/* resolve the fully-qualified path name to use as the hash key */
737-
fullpath = expand_filepath(filename, NULL TSRMLS_CC);
736+
if (strncmp(filename, ":memory:", sizeof(":memory:") - 1)) {
737+
/* resolve the fully-qualified path name to use as the hash key */
738+
fullpath = expand_filepath(filename, NULL TSRMLS_CC);
738739

739-
if (PG(safe_mode) && (!php_checkuid(fullpath, NULL, CHECKUID_CHECK_FILE_AND_DIR))) {
740-
RETURN_FALSE;
741-
}
740+
if (PG(safe_mode) && (!php_checkuid(fullpath, NULL, CHECKUID_CHECK_FILE_AND_DIR))) {
741+
RETURN_FALSE;
742+
}
742743

743-
if (php_check_open_basedir(fullpath TSRMLS_CC)) {
744-
RETURN_FALSE;
744+
if (php_check_open_basedir(fullpath TSRMLS_CC)) {
745+
RETURN_FALSE;
746+
}
747+
} else {
748+
fullpath = estrndup(filename, filename_len);
745749
}
746750

747751
hashkeylen = spprintf(&hashkey, 0, "sqlite_pdb_%s:%d", fullpath, mode);
@@ -791,12 +795,14 @@ PHP_FUNCTION(sqlite_open)
791795
return;
792796
}
793797

794-
if (PG(safe_mode) && (!php_checkuid(filename, NULL, CHECKUID_CHECK_FILE_AND_DIR))) {
795-
RETURN_FALSE;
796-
}
798+
if (strncmp(filename, ":memory:", sizeof(":memory:") - 1)) {
799+
if (PG(safe_mode) && (!php_checkuid(filename, NULL, CHECKUID_CHECK_FILE_AND_DIR))) {
800+
RETURN_FALSE;
801+
}
797802

798-
if (php_check_open_basedir(filename TSRMLS_CC)) {
799-
RETURN_FALSE;
803+
if (php_check_open_basedir(filename TSRMLS_CC)) {
804+
RETURN_FALSE;
805+
}
800806
}
801807

802808
php_sqlite_open(filename, mode, NULL, return_value, errmsg TSRMLS_CC);

0 commit comments

Comments
 (0)