From 49094570c4e95e94eb4f030f228ea8b0742d23f8 Mon Sep 17 00:00:00 2001 From: DL6ER Date: Fri, 23 Apr 2021 17:29:10 +0200 Subject: [PATCH] Enable compile-time flag SQLITE_ENABLE_DBPAGE_VTAB to add support for .recover shell option. Signed-off-by: DL6ER --- src/CMakeLists.txt | 3 ++- src/database/common.c | 11 +++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 5dc4ce6d..8bb76921 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -26,7 +26,8 @@ set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}) # SQLITE_OMIT_PROGRESS_CALLBACK: The progress handler callback counter must be checked in the inner loop of the bytecode engine. By omitting this interface, a single conditional is removed from the inner loop of the bytecode engine, helping SQL statements to run slightly faster. # SQLITE_DEFAULT_FOREIGN_KEYS=1: This macro determines whether enforcement of foreign key constraints is enabled or disabled by default for new database connections. # SQLITE_DQS=0: This setting disables the double-quoted string literal misfeature. -set(SQLITE_DEFINES "-DSQLITE_OMIT_LOAD_EXTENSION -DSQLITE_DEFAULT_MEMSTATUS=0 -DSQLITE_OMIT_DEPRECATED -DSQLITE_OMIT_PROGRESS_CALLBACK -DSQLITE_DEFAULT_FOREIGN_KEYS=1 -DSQLITE_DQS=0") +# SQLITE_ENABLE_DBPAGE_VTAB: Enables the SQLITE_DBPAGE virtual table. Warning: writing to the SQLITE_DBPAGE virtual table can very easily cause unrecoverably database corruption. +set(SQLITE_DEFINES "-DSQLITE_OMIT_LOAD_EXTENSION -DSQLITE_DEFAULT_MEMSTATUS=0 -DSQLITE_OMIT_DEPRECATED -DSQLITE_OMIT_PROGRESS_CALLBACK -DSQLITE_DEFAULT_FOREIGN_KEYS=1 -DSQLITE_DQS=0 -DSQLITE_ENABLE_DBPAGE_VTAB") # Code hardening and debugging improvements # -fstack-protector-strong: The program will be resistant to having its stack overflowed diff --git a/src/database/common.c b/src/database/common.c index df4cd751..2a1a7141 100644 --- a/src/database/common.c +++ b/src/database/common.c @@ -193,6 +193,17 @@ void db_init(void) // explicitly check for failures to have happened sqlite3_config(SQLITE_CONFIG_LOG, SQLite3LogCallback, NULL); + // SQLITE_DBCONFIG_DEFENSIVE + // Disbale language features that allow ordinary SQL to deliberately corrupt + // the database file. The disabled features include but are not limited to + // the following: + // + // - The PRAGMA writable_schema=ON statement. + // - The PRAGMA journal_mode=OFF statement. + // - Writes to the sqlite_dbpage virtual table. + // - Direct writes to shadow tables. + sqlite3_config(SQLITE_DBCONFIG_DEFENSIVE, true); + // Register Pi-hole provided SQLite3 extensions (see sqlite3-ext.c) sqlite3_auto_extension((void (*)(void))sqlite3_pihole_extensions_init);