From ceae3caa37cb631166f4d23c03c4d0056cf77fd3 Mon Sep 17 00:00:00 2001 From: hawk Date: Sun, 10 Feb 2019 10:06:59 +0500 Subject: [PATCH] sqlite3 databases: check that the file exists and is writeable --- functions.inc.php | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/functions.inc.php b/functions.inc.php index fc234fbb..c1c1cfd4 100644 --- a/functions.inc.php +++ b/functions.inc.php @@ -1484,7 +1484,19 @@ function db_connect_with_errors() { $queries[] = 'SET CHARACTER SET utf8'; $queries[] = "SET COLLATION_CONNECTION='utf8_general_ci'"; } elseif (db_sqlite()) { - $dsn = "sqlite:{$CONF['database_name']}"; + $db = $CONF['database_name']; + + if (!file_exists($db)) { + $error_text = 'SQLite database missing: '. $db; + return array($link, $error_text); + } + + if (!is_writeable($db)) { + $error_text = 'SQLite database not writeable: '. $db; + return array($link, $error_text); + } + + $dsn = "sqlite:{$db}"; $username_password = false; } elseif (db_pgsql()) { if (!isset($CONF['database_port'])) { @@ -1509,7 +1521,6 @@ function db_connect_with_errors() { } } catch (PDOException $e) { $error_text = 'PDO exception: '. $e->getMessage(); - error_log($error_text); } return array($link, $error_text);