[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.
This commit is contained in:
Noah R committed 2026-07-10 17:52:55 -07:00
1 parent b3e8074890
commit f056be140c
1 file changed
+2 -2
+2 -2
View File
@@ -425,7 +425,7 @@ GncDbiBackend<DbType::DBI_SQLITE>::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<Type>::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");