From d3434960842a8405a4fd4e2e7b43f2f4a7075a0b Mon Sep 17 00:00:00 2001 From: James Turner Date: Thu, 26 Jan 2017 20:35:25 +0000 Subject: [PATCH] Check nav-cache write-ability explicitly. Check the file permissions before opening using the new SGPath APIs, and validate the result using Sqlite APIs after opening. --- src/Navaids/NavDataCache.cxx | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/Navaids/NavDataCache.cxx b/src/Navaids/NavDataCache.cxx index 4c919bc95..efe600e76 100644 --- a/src/Navaids/NavDataCache.cxx +++ b/src/Navaids/NavDataCache.cxx @@ -261,6 +261,9 @@ public: SG_LOG(SG_NAVCACHE, SG_INFO, "NavCache at:" << path); readOnly = fgGetBool("/sim/fghome-readonly", false); + if (!readOnly && !path.canWrite()) { + throw sg_exception("Nav-cache file is not writeable"); + } int openFlags = readOnly ? SQLITE_OPEN_READONLY : SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE; @@ -276,6 +279,10 @@ public: throw sg_exception("Navcache failed to open:" + errMsg); } + if (!readOnly && (sqlite3_db_readonly(db, nullptr) != 0)) { + throw sg_exception("Nav-cache file opened but is not writeable"); + } + sqlite3_stmt_ptr checkTables = prepare("SELECT count(*) FROM sqlite_master WHERE name='properties'");