1
0
mirror of https://github.com/vrana/adminer.git synced 2025-08-07 23:27:17 +02:00

Disable creating SQLite databases with extension other than db, sdb, sqlite

This commit is contained in:
Jakub Vrana
2010-10-17 08:22:36 +02:00
parent 644c355d94
commit 51e609c461
2 changed files with 19 additions and 1 deletions

View File

@@ -344,13 +344,27 @@ if (isset($_GET["sqlite"]) || isset($_GET["sqlite2"])) {
function exact_value($val) {
return q($val);
}
function check_sqlite_name($name) {
// avoid creating PHP files on unsecured servers
global $connection;
$extensions = "db|sdb|sqlite";
if (!preg_match("~^[^\\0]*\\.($extensions)\$~", $name)) {
$connection->error = lang('Please use one of the extensions %s.', str_replace("|", ", ", $extensions));
return false;
}
return true;
}
function create_database($db, $collation) {
global $connection;
if (file_exists($db)) {
$connection->error = lang('File exists.');
return false;
}
if (!check_sqlite_name($db)) {
return false;
}
$link = new Min_SQLite($db); //! exception handler
$link->query('PRAGMA encoding = "UTF-8"');
$link->query('CREATE TABLE adminer (i)'); // otherwise creates empty file
@@ -372,6 +386,9 @@ if (isset($_GET["sqlite"]) || isset($_GET["sqlite2"])) {
function rename_database($name, $collation) {
global $connection;
if (!check_sqlite_name($name)) {
return false;
}
$connection->Min_SQLite(":memory:");
$connection->error = lang('File exists.');
return @rename(DB, $name);