1 minor finding · 2 suggestions
Findings
[minor] · Prefix cursor buffers are freed before their statement is finalized
Destroying a successfully constructed nonempty prefix cursor leaves its SQLITE_STATIC bindings pointing to freed vector storage until finalization, violating SQLite's lifetime contract without an established invalid read.
Location: src/wallet/sqlite.h:25 (head).
Details and suggested fix
m_cursor_stmt is declared before the two prefix vectors, so the defaulted destructor destroys the vectors first and only then calls sqlite3_finalize through ~SQLiteStatement. The prefix constructor binds those vectors with SQLITE_STATIC, which requires their storage to remain valid until finalization or replacement of the bindings. Neither Next() nor the destructor clears successful bindings first. This also applies to early destruction, such as WalletBatch::IsEncrypted returning after its first row. The previous destructor cleared and finalized the statement in its body while the vectors were still alive. Declare the vectors before m_cursor_stmt and reorder the initializer list so the statement is destroyed first; binding occurs in the constructor body, so this preserves construction behavior. No actual read of the expired buffers during finalization was established.
Optional improvements
[suggestion] · Recoverable statement failures now produce generic error-level logs
The shared executor raises handled write failures from warning to error level and removes the previous write-versus-erase context.
Location: src/wallet/sqlite.cpp:543 (head).
Details and suggested fix
ExecStatement now logs every non-SQLITE_DONE result with LogError, including a duplicate insert with overwrite=false. That failure resets the statement, releases the semaphore outside a transaction, and returns false; it does not require wallet shutdown. The SQLite-backed db_availability_after_write_error test expects this failure followed by successful overwrite and read, while doc/developer-notes.md reserves LogError for problems requiring node or subsystem shutdown. Restore LogWarning and pass an operation description into the shared executor to retain diagnostic context without changing recovery. WriteCryptedKey also contains a duplicate-record fallback, but no current SQLite production caller exercising that fallback was confirmed, so its contribution to log frequency remains unconfirmed.
[suggestion] · BLOB accessor no longer guarantees blob-before-bytes evaluation
The inlined accessor loses SQLite's documented safe call order, although wallet-written BLOBs need no conversion and no concrete misread was established.
Location: src/wallet/sqlite.cpp:135 (head).
Details and suggested fix
ColumnBlob passes sqlite3_column_blob and sqlite3_column_bytes as parenthesized constructor arguments, whose evaluation order is unspecified. The removed SpanFromBlob used a braced initializer, which guaranteed blob first and then bytes, matching SQLite's documented safe sequence. ReadKey and SQLiteCursor::Next use this branch for wallet records. Assign the pointer and size to separate locals in that order before constructing T, as the string branch already does for text. Wallet writes bind both fields as BLOBs, so either order gives the same result for wallet-written data. The conversion concern is limited to non-BLOB values in a locally modified or foreign file; no differing read was established.