db: tidy db_col_psbt NULL handling
What changed, and why it matters
This commit fixes a helper function that reads PSBT data from the database. Previously, when the database column was NULL, the code would still try to parse it and unconditionally set the PSBT version, which could lead to a crash or undefined behavior. Now it returns NULL early for NULL columns, matching the behavior of similar helper functions, and only sets the version when parsing actually succeeded.
Review callers of db_col_psbt() to ensure they handle NULL returns correctly, and consider backporting this fix to stable branches. No immediate emergency response is indicated, but the fix should be included in the next maintenance release.
Security signals we found
NULL pointer handling fix
Defensive consistency fix across db_col_* helpers
Potential crash/DoS mitigation on malformed or NULL database values
Evidence from the diff
In db/bindings.c, db_col_psbt() now returns NULL immediately when db_column_null_warn() reports a NULL column, consistent with other db_col_* helpers. It also only calls psbt_set_version(psbt, 2) when psbt_from_bytes() returns a non-NULL PSBT. This prevents potential NULL pointer dereference or use-after-free/undefined behavior from calling psbt_set_version on a NULL or invalid PSBT parsed from a NULL/empty blob.
Changed components
db/bindings.cdb_col_psbt()PSBT database deserializationInspect captured patch +5 / −2
### db/bindings.c
@@ -496,9 +496,12 @@ struct wally_psbt *db_col_psbt(const tal_t *ctx, struct db_stmt *stmt, const cha
const u8 *src = db_column_blob(stmt, col);
size_t len = db_column_bytes(stmt, col);
- db_column_null_warn(stmt, colname, col);
+ if (db_column_null_warn(stmt, colname, col))
+ return NULL;
+
psbt = psbt_from_bytes(ctx, src, len);
- psbt_set_version(psbt, 2);
+ if (psbt)
+ psbt_set_version(psbt, 2);
return psbt;
}
Why this scored 32/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.