Skip to content

Commit 82d5507

Browse files
committed
Check preupdate value fetch result to avoid NULL dereference
1 parent 78710fc commit 82d5507

1 file changed

Lines changed: 6 additions & 2 deletions

File tree

sqlite3_opt_preupdate_hook.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,13 +59,17 @@ func (d *SQLitePreUpdateData) row(dest []any, new bool) error {
5959
for i := 0; i < d.Count() && i < len(dest); i++ {
6060
var val *C.sqlite3_value
6161
var src any
62+
var rc C.int
6263

6364
// Initially I tried making this just a function pointer argument, but
6465
// it's absurdly complicated to pass C function pointers.
6566
if new {
66-
C.sqlite3_preupdate_new(d.Conn.db, C.int(i), &val)
67+
rc = C.sqlite3_preupdate_new(d.Conn.db, C.int(i), &val)
6768
} else {
68-
C.sqlite3_preupdate_old(d.Conn.db, C.int(i), &val)
69+
rc = C.sqlite3_preupdate_old(d.Conn.db, C.int(i), &val)
70+
}
71+
if rc != C.SQLITE_OK {
72+
return Error{Code: ErrNo(rc)}
6973
}
7074

7175
switch C.sqlite3_value_type(val) {

0 commit comments

Comments
 (0)