Commit 432562a
committed
Fix use-after-free in exqlite_interrupt: add interrupt_mutex; NULL guard execute
exqlite_interrupt() read conn->db and called sqlite3_interrupt() without any
lock, while a concurrent close() could sqlite3_close_v2() and NULL conn->db
between the read and the call → use-after-free / segfault.
The connection lock cannot be used here: running queries hold it for their
full duration, and interrupt() must not block waiting for them to finish.
Add a dedicated interrupt_mutex to connection_t. close() acquires it after
sqlite3_close_v2() sets conn->db = NULL, and interrupt() acquires it before
reading conn->db. This eliminates the TOCTOU entirely.
Also add a conn->db == NULL guard inside the lock in exqlite_execute so that
a racing call to execute after close returns an error rather than crashing.1 parent eff42e3 commit 432562a
2 files changed
Lines changed: 43 additions & 18 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
52 | 52 | | |
53 | 53 | | |
54 | 54 | | |
| 55 | + | |
55 | 56 | | |
56 | 57 | | |
57 | 58 | | |
| |||
336 | 337 | | |
337 | 338 | | |
338 | 339 | | |
339 | | - | |
340 | | - | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
| 343 | + | |
| 344 | + | |
| 345 | + | |
| 346 | + | |
| 347 | + | |
341 | 348 | | |
342 | 349 | | |
343 | 350 | | |
| |||
398 | 405 | | |
399 | 406 | | |
400 | 407 | | |
| 408 | + | |
| 409 | + | |
| 410 | + | |
401 | 411 | | |
| 412 | + | |
| 413 | + | |
402 | 414 | | |
403 | 415 | | |
404 | 416 | | |
| |||
431 | 443 | | |
432 | 444 | | |
433 | 445 | | |
| 446 | + | |
| 447 | + | |
| 448 | + | |
| 449 | + | |
| 450 | + | |
434 | 451 | | |
435 | 452 | | |
436 | 453 | | |
| |||
1171 | 1188 | | |
1172 | 1189 | | |
1173 | 1190 | | |
| 1191 | + | |
| 1192 | + | |
| 1193 | + | |
| 1194 | + | |
| 1195 | + | |
1174 | 1196 | | |
1175 | 1197 | | |
1176 | 1198 | | |
| |||
1477 | 1499 | | |
1478 | 1500 | | |
1479 | 1501 | | |
1480 | | - | |
1481 | | - | |
1482 | | - | |
1483 | | - | |
1484 | | - | |
1485 | | - | |
1486 | | - | |
1487 | | - | |
| 1502 | + | |
| 1503 | + | |
| 1504 | + | |
| 1505 | + | |
| 1506 | + | |
| 1507 | + | |
| 1508 | + | |
| 1509 | + | |
| 1510 | + | |
| 1511 | + | |
| 1512 | + | |
| 1513 | + | |
| 1514 | + | |
| 1515 | + | |
1488 | 1516 | | |
1489 | 1517 | | |
1490 | 1518 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
659 | 659 | | |
660 | 660 | | |
661 | 661 | | |
662 | | - | |
| 662 | + | |
663 | 663 | | |
664 | 664 | | |
665 | | - | |
666 | | - | |
667 | 665 | | |
668 | 666 | | |
669 | 667 | | |
| |||
845 | 843 | | |
846 | 844 | | |
847 | 845 | | |
848 | | - | |
849 | | - | |
850 | | - | |
851 | | - | |
852 | | - | |
| 846 | + | |
| 847 | + | |
| 848 | + | |
| 849 | + | |
853 | 850 | | |
854 | 851 | | |
855 | 852 | | |
| |||
0 commit comments