Commit 8adcb3b
committed
sqlite: fix crash on db.close() from inside a user function
Calling db.close() from inside a user-defined function callback while
sqlite3_step is on the call stack caused two distinct crashes:
1. DatabaseSync::Close ran sqlite3_finalize on the statement whose
sqlite3_step frame was still active, freeing the VM that step was
executing. The outer step then operated on freed memory.
2. Even if (1) is avoided, StatementExecutionHelper::Run dereferenced
db->Connection() via sqlite3_last_insert_rowid / sqlite3_changes64
after step returned. The reentrant close zeroed connection_, so
the deref crashed.
Add a MarkStepping() RAII guard wrapped around every sqlite3_step
caller. If Finalize() is called while stepping_, defer it; the
guard's destructor runs the deferred finalize after step returns.
Add a connection-null check in StatementExecutionHelper::Run before
the connection-dependent reads, throwing ERR_INVALID_STATE.
Fixes: #63180
Signed-off-by: Matthew McEachen <matthew@photostructure.com>1 parent dc99d18 commit 8adcb3b
3 files changed
Lines changed: 119 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2563 | 2563 | | |
2564 | 2564 | | |
2565 | 2565 | | |
| 2566 | + | |
| 2567 | + | |
| 2568 | + | |
| 2569 | + | |
| 2570 | + | |
| 2571 | + | |
| 2572 | + | |
2566 | 2573 | | |
2567 | 2574 | | |
2568 | 2575 | | |
| |||
2888 | 2895 | | |
2889 | 2896 | | |
2890 | 2897 | | |
| 2898 | + | |
| 2899 | + | |
| 2900 | + | |
| 2901 | + | |
2891 | 2902 | | |
2892 | 2903 | | |
2893 | 2904 | | |
| |||
3016 | 3027 | | |
3017 | 3028 | | |
3018 | 3029 | | |
3019 | | - | |
3020 | | - | |
3021 | 3030 | | |
| 3031 | + | |
| 3032 | + | |
3022 | 3033 | | |
3023 | 3034 | | |
3024 | 3035 | | |
| |||
3066 | 3077 | | |
3067 | 3078 | | |
3068 | 3079 | | |
| 3080 | + | |
3069 | 3081 | | |
3070 | 3082 | | |
3071 | 3083 | | |
| |||
3090 | 3102 | | |
3091 | 3103 | | |
3092 | 3104 | | |
| 3105 | + | |
3093 | 3106 | | |
3094 | 3107 | | |
3095 | 3108 | | |
| |||
3354 | 3367 | | |
3355 | 3368 | | |
3356 | 3369 | | |
| 3370 | + | |
3357 | 3371 | | |
3358 | 3372 | | |
3359 | 3373 | | |
| |||
3425 | 3439 | | |
3426 | 3440 | | |
3427 | 3441 | | |
| 3442 | + | |
3428 | 3443 | | |
3429 | 3444 | | |
3430 | 3445 | | |
| |||
3463 | 3478 | | |
3464 | 3479 | | |
3465 | 3480 | | |
3466 | | - | |
3467 | 3481 | | |
| 3482 | + | |
| 3483 | + | |
3468 | 3484 | | |
3469 | 3485 | | |
3470 | 3486 | | |
| |||
3691 | 3707 | | |
3692 | 3708 | | |
3693 | 3709 | | |
| 3710 | + | |
3694 | 3711 | | |
3695 | 3712 | | |
3696 | 3713 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
284 | 284 | | |
285 | 285 | | |
286 | 286 | | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
287 | 300 | | |
288 | 301 | | |
289 | 302 | | |
| |||
295 | 308 | | |
296 | 309 | | |
297 | 310 | | |
| 311 | + | |
| 312 | + | |
298 | 313 | | |
299 | 314 | | |
300 | 315 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
411 | 411 | | |
412 | 412 | | |
413 | 413 | | |
| 414 | + | |
| 415 | + | |
| 416 | + | |
| 417 | + | |
| 418 | + | |
| 419 | + | |
| 420 | + | |
| 421 | + | |
| 422 | + | |
| 423 | + | |
| 424 | + | |
| 425 | + | |
| 426 | + | |
| 427 | + | |
| 428 | + | |
| 429 | + | |
| 430 | + | |
| 431 | + | |
| 432 | + | |
| 433 | + | |
| 434 | + | |
| 435 | + | |
| 436 | + | |
| 437 | + | |
| 438 | + | |
| 439 | + | |
| 440 | + | |
| 441 | + | |
| 442 | + | |
| 443 | + | |
| 444 | + | |
| 445 | + | |
| 446 | + | |
| 447 | + | |
| 448 | + | |
| 449 | + | |
| 450 | + | |
| 451 | + | |
| 452 | + | |
| 453 | + | |
| 454 | + | |
| 455 | + | |
| 456 | + | |
| 457 | + | |
| 458 | + | |
| 459 | + | |
| 460 | + | |
| 461 | + | |
| 462 | + | |
| 463 | + | |
| 464 | + | |
| 465 | + | |
| 466 | + | |
| 467 | + | |
| 468 | + | |
| 469 | + | |
| 470 | + | |
| 471 | + | |
| 472 | + | |
| 473 | + | |
| 474 | + | |
| 475 | + | |
| 476 | + | |
| 477 | + | |
| 478 | + | |
| 479 | + | |
| 480 | + | |
| 481 | + | |
| 482 | + | |
| 483 | + | |
| 484 | + | |
| 485 | + | |
| 486 | + | |
| 487 | + | |
| 488 | + | |
| 489 | + | |
| 490 | + | |
| 491 | + | |
| 492 | + | |
| 493 | + | |
| 494 | + | |
| 495 | + | |
| 496 | + | |
| 497 | + | |
414 | 498 | | |
0 commit comments