From 44d57e5b37f19b4fff91eba0735fca2a1a33b9f1 Mon Sep 17 00:00:00 2001 From: DL6ER Date: Thu, 6 Jun 2024 06:45:53 +0200 Subject: [PATCH] Add checking of return status of sqlite3_open_v2 to ensure we are not trying to use the database when it failed to open Signed-off-by: DL6ER --- src/database/gravity-db.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/database/gravity-db.c b/src/database/gravity-db.c index d922e2d7..f0ac7398 100644 --- a/src/database/gravity-db.c +++ b/src/database/gravity-db.c @@ -28,9 +28,10 @@ #include "datastructure.h" // reset_aliasclient() #include "aliasclients.h" - // Definition of struct regexData #include "regex_r.h" +// file_readable() +#include "files.h" // Prefix of interface names in the client table #define INTERFACE_SEP ":" @@ -2715,9 +2716,17 @@ bool gravity_updated(void) sqlite3 *db = NULL; sqlite3_stmt *query_stmt = NULL; + // Check if database is a readable file + if(file_readable(config.files.gravity.v.s) == false) + { + log_err("Cannot read gravity database at %s - file does not exist or is not readable", + config.files.gravity.v.s); + return false; + } + // Open database int rc = sqlite3_open_v2(config.files.gravity.v.s, &db, SQLITE_OPEN_READONLY, NULL); - if(db == NULL) + if(db == NULL || rc != SQLITE_OK) { log_err("gravity_updated(): %s - SQL error open: %s", config.files.gravity.v.s, sqlite3_errstr(rc)); return false;