Skip to content

Commit 1d858b0

Browse files
ryanofskyachow101
authored andcommitted
walletdb: Handle when database keys are empty
1 parent 84b2f35 commit 1d858b0

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

src/wallet/bdb.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -691,7 +691,7 @@ DatabaseCursor::Status BerkeleyCursor::Next(DataStream& ssKey, DataStream& ssVal
691691
if (ret == DB_NOTFOUND) {
692692
return Status::DONE;
693693
}
694-
if (ret != 0 || datKey.get_data() == nullptr || datValue.get_data() == nullptr) {
694+
if (ret != 0) {
695695
return Status::FAIL;
696696
}
697697

src/wallet/sqlite.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,11 @@ static bool BindBlobToStatement(sqlite3_stmt* stmt,
3939
Span<const std::byte> blob,
4040
const std::string& description)
4141
{
42-
int res = sqlite3_bind_blob(stmt, index, blob.data(), blob.size(), SQLITE_STATIC);
42+
// Pass a pointer to the empty string "" below instead of passing the
43+
// blob.data() pointer if the blob.data() pointer is null. Passing a null
44+
// data pointer to bind_blob would cause sqlite to bind the SQL NULL value
45+
// instead of the empty blob value X'', which would mess up SQL comparisons.
46+
int res = sqlite3_bind_blob(stmt, index, blob.data() ? static_cast<const void*>(blob.data()) : "", blob.size(), SQLITE_STATIC);
4347
if (res != SQLITE_OK) {
4448
LogPrintf("Unable to bind %s to statement: %s\n", description, sqlite3_errstr(res));
4549
sqlite3_clear_bindings(stmt);

0 commit comments

Comments
 (0)