From f056be140cd9b929d7cd2aef560eeeeb2880f3ac Mon Sep 17 00:00:00 2001 From: Noah R Date: Fri, 10 Jul 2026 17:52:38 -0700 Subject: [PATCH] [backend/dbi] skip the libdbi integrity probe for read-only sessions session_begin() runs dbi_library_test() (Bug #611936) on every open to detect a libdbi/-ffast-math miscompilation that mangles 64-bit values. The probe CREATEs, INSERTs into, SELECTs from and DROPs a temporary table, so it needs write privileges on the database -- even for SESSION_READ_ONLY. A least-privilege, read-only database user therefore cannot open the book at all: the temporary-table create fails and session_begin returns ERR_SQL_DBI_UNTESTABLE. The defect the probe guards against is on the write side of libdbi, so it can be neither triggered nor detected by a read-only session, which never writes. Skip the probe when the session is opened SESSION_READ_ONLY, at the two call sites a read-only open reaches (the SQLite session_begin and the shared MySQL/PostgreSQL session_begin); the third call site is inside the create branch, which read-only never enters. The write-capable modes (NORMAL_OPEN, NEW_STORE, NEW_OVERWRITE, BREAK_LOCK) still run the probe unchanged. This lets a SELECT-only database user open a book read-only through the API. --- libgnucash/backend/dbi/gnc-backend-dbi.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libgnucash/backend/dbi/gnc-backend-dbi.cpp b/libgnucash/backend/dbi/gnc-backend-dbi.cpp index 08c0baa805..cbc2f3d820 100644 --- a/libgnucash/backend/dbi/gnc-backend-dbi.cpp +++ b/libgnucash/backend/dbi/gnc-backend-dbi.cpp @@ -425,7 +425,7 @@ GncDbiBackend::session_begin(QofSession* session, return; } - if (!conn_test_dbi_library(conn)) + if (mode != SESSION_READ_ONLY && !conn_test_dbi_library(conn)) { if (create && !file_exists) { @@ -677,7 +677,7 @@ GncDbiBackend::session_begin (QofSession* session, const char* new_uri, { if (Type == DbType::DBI_MYSQL) adjust_sql_options (conn); - if(!conn_test_dbi_library(conn)) + if (mode != SESSION_READ_ONLY && !conn_test_dbi_library(conn)) { dbi_conn_close(conn); LEAVE("Error");