-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Add pdo_sqlite tests for empty filename and in-memory uri #7662
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
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
--TEST-- | ||
PDO_sqlite: Testing empty filename | ||
--EXTENSIONS-- | ||
pdo_sqlite | ||
--FILE-- | ||
<?php | ||
|
||
// create with empty filename | ||
$db = new PDO('sqlite:'); | ||
|
||
var_dump($db->exec('CREATE TABLE test1 (id INT);')); | ||
|
||
// create with empty URI | ||
$db = new PDO('sqlite:file:?cache=shared'); | ||
|
||
var_dump($db->exec('CREATE TABLE test1 (id INT);')); | ||
?> | ||
--EXPECT-- | ||
int(0) | ||
int(0) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
--TEST-- | ||
PDO_sqlite: Testing filenames with open_basedir | ||
--EXTENSIONS-- | ||
pdo_sqlite | ||
--INI-- | ||
open_basedir=. | ||
--FILE-- | ||
<?php | ||
|
||
// create in basedir | ||
$filename = 'pdo_sqlite_filename.db'; | ||
|
||
$db = new PDO('sqlite:' . $filename); | ||
|
||
var_dump($db->exec('CREATE TABLE test1 (id INT);')); | ||
|
||
// create outside basedir | ||
$filename = '..' . DIRECTORY_SEPARATOR . 'pdo_sqlite_filename.db'; | ||
|
||
new PDO('sqlite:' . $filename); | ||
?> | ||
|
||
--CLEAN-- | ||
<?php | ||
$filenames = [ | ||
'pdo_sqlite_filename.db', | ||
'..' . DIRECTORY_SEPARATOR . 'pdo_sqlite_filename.db', | ||
]; | ||
foreach ($filenames as $filename) { | ||
if (file_exists($filename)) { | ||
unlink($filename); | ||
} | ||
} | ||
?> | ||
--EXPECTF-- | ||
int(0) | ||
|
||
Fatal error: Uncaught PDOException: PDO::__construct(): open_basedir restriction in effect. File(%s) is not within the allowed path(s): (%s) in %s:%d | ||
Stack trace: | ||
%s | ||
#1 {main} | ||
|
||
Next PDOException: open_basedir prohibits opening %s in %s:%d | ||
Stack trace: | ||
%s | ||
#1 {main} | ||
thrown in %s |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
--TEST-- | ||
PDO_sqlite: Testing URIs with open_basedir | ||
--EXTENSIONS-- | ||
pdo_sqlite | ||
--INI-- | ||
open_basedir={TMP} | ||
--FILE-- | ||
<?php | ||
|
||
// create in basedir | ||
$filename = sys_get_temp_dir() . DIRECTORY_SEPARATOR . 'pdo_sqlite_filename.db'; | ||
|
||
new PDO('sqlite:file:' . $filename); | ||
?> | ||
|
||
--CLEAN-- | ||
<?php | ||
$filenames = [ | ||
sys_get_temp_dir() . DIRECTORY_SEPARATOR . 'pdo_sqlite_filename.db', | ||
]; | ||
foreach ($filenames as $filename) { | ||
if (file_exists($filename)) { | ||
unlink($filename); | ||
} | ||
} | ||
?> | ||
--EXPECTF-- | ||
Fatal error: Uncaught PDOException: open_basedir prohibits opening %s in %s:%d | ||
Stack trace: | ||
%s | ||
#1 {main} | ||
thrown in %s |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this also open a second connection to check that it is actually shared?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It could. I don't know if php is responsible for all the uri options working though. I was mainly testing the special case filenames.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Given that we don't directly pass the DSN to SQLite3, that additional check would make sense. It may also make sense to add an INI section with
open_basedir=
, because if open_basedir is set,file:
URIs are not supported by PHP.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FreeBSD fails for some reason. What is the recommended open_basedir setting and then target directory to use to trigger a fail on all platforms?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you could use
open_basedir=.
for that.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And write to what directory? If it doesn't restrict and creates a file, does it matter where it goes?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Found an example test to follow.