Handle NULL database strings safely

SQLite returns a null pointer for SQL NULL. Passing it to rust::Str
crashes the daemon when a query result contains a NULL column.

Return an empty Rust string for NULL while leaving the raw C++ getter
unchanged, so callers that distinguish NULL can keep doing so.

Fixes: #10131
Assisted-by: GPT-6
This commit is contained in:
fhgffy
2026-10-05 22:06:05 -07:00
committed by John Wu
parent 441ac32623
commit 806ecdf8e8
+4 -1
View File
@@ -20,7 +20,10 @@ extern const char *(*sqlite3_errstr)(int);
// Transparent wrappers of sqlite3_stmt
struct DbValues {
const char *get_text(int index) const;
rust::Str get_str(int index) const { return get_text(index); }
rust::Str get_str(int index) const {
auto text = get_text(index);
return text ? rust::Str(text) : rust::Str();
}
int get_int(int index) const;
~DbValues() = delete;
};