From bf3cca8639251fc2464c4d93bc01a1e898c42be0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Canna=C3=B2?= Date: Wed, 2 Apr 2025 10:19:24 +0000 Subject: [PATCH] exit if database file is not writable If database file (proxysql.db) is not writable, exit immediately instead of crashing because it is not writable. See issue #4893 --- lib/Admin_Bootstrap.cpp | 4 ++++ lib/ProxySQL_Admin.cpp | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/lib/Admin_Bootstrap.cpp b/lib/Admin_Bootstrap.cpp index c9d971ac6..4ffc62ef5 100644 --- a/lib/Admin_Bootstrap.cpp +++ b/lib/Admin_Bootstrap.cpp @@ -520,6 +520,10 @@ bool ProxySQL_Admin::init(const bootstrap_info_t& bootstrap_info) { bool admindb_file_exists=Proxy_file_exists(GloVars.admindb); configdb=new SQLite3DB(); + if (access(GloVars.admindb, W_OK) != 0) { + proxy_error("Database file '%s' is not writable\n", GloVars.admindb); + exit(EXIT_SUCCESS); + } configdb->open((char *)GloVars.admindb, SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE | SQLITE_OPEN_FULLMUTEX); // Fully synchronous is not required. See to #1055 // https://sqlite.org/pragma.html#pragma_synchronous diff --git a/lib/ProxySQL_Admin.cpp b/lib/ProxySQL_Admin.cpp index 8155bd349..3ab3b1385 100644 --- a/lib/ProxySQL_Admin.cpp +++ b/lib/ProxySQL_Admin.cpp @@ -1134,6 +1134,10 @@ void ProxySQL_Admin::flush_configdb() { // see #923 admindb->execute((char *)"DETACH DATABASE disk"); delete configdb; configdb=new SQLite3DB(); + if (access(GloVars.admindb, W_OK) != 0) { + proxy_error("Database file '%s' is not writable\n", GloVars.admindb); + exit(EXIT_SUCCESS); + } configdb->open((char *)GloVars.admindb, SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE | SQLITE_OPEN_FULLMUTEX); __attach_db(admindb, configdb, (char *)"disk"); // Fully synchronous is not required. See to #1055