forked frompostgres/postgres
- Notifications
You must be signed in to change notification settings - Fork6
Commit27c6619
committed
Fix possible dangling pointer dereference in trigger.c.
AfterTriggerEndQuery correctly notes that the query_stack could getrepalloc'd during a trigger firing, but it nonetheless passes the addressof a query_stack entry to afterTriggerInvokeEvents, so that if such arepalloc occurs, afterTriggerInvokeEvents is already working with anobsolete dangling pointer while it scans the rest of the events. Oops.The only code at risk is its "delete_ok" cleanup code, so we canprevent unsafe behavior by passing delete_ok = false instead of true.However, that could have a significant performance penalty, because thepoint of passing delete_ok = true is to not have to re-scan possiblya large number of dead trigger events on the next time through the loop.There's more than one way to skin that cat, though. What we can do isdelete all the "chunks" in the event list except the last one, sincewe know all events in them must be dead. Deleting the chunks is workwe'd have had to do later in AfterTriggerEndQuery anyway, and it endsup saving rescanning of just about the same events we'd have gottenrid of with delete_ok = true.In v10 and HEAD, we also have to be careful to mop up any per-tableafter_trig_events pointers that would become dangling. This is slightlyannoying, but I don't think that normal use-cases will traverse this codepath often enough for it to be a performance problem.It's pretty hard to hit this in practice because of the unlikelihoodof the query_stack getting resized at just the wrong time. Nonetheless,it's definitely a live bug of ancient standing, so back-patch to allsupported branches.Discussion:https://postgr.es/m/2891.1505419542@sss.pgh.pa.us1 parentfd31f9f commit27c6619
1 file changed
+71
-15
lines changedLines changed: 71 additions & 15 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
3831 | 3831 |
| |
3832 | 3832 |
| |
3833 | 3833 |
| |
3834 |
| - | |
3835 | 3834 |
| |
3836 |
| - | |
| 3835 | + | |
3837 | 3836 |
| |
3838 |
| - | |
| 3837 | + | |
3839 | 3838 |
| |
3840 | 3839 |
| |
3841 |
| - | |
3842 | 3840 |
| |
3843 | 3841 |
| |
3844 | 3842 |
| |
| |||
3882 | 3880 |
| |
3883 | 3881 |
| |
3884 | 3882 |
| |
| 3883 | + | |
| 3884 | + | |
| 3885 | + | |
| 3886 | + | |
| 3887 | + | |
| 3888 | + | |
| 3889 | + | |
| 3890 | + | |
| 3891 | + | |
| 3892 | + | |
| 3893 | + | |
| 3894 | + | |
| 3895 | + | |
| 3896 | + | |
| 3897 | + | |
| 3898 | + | |
| 3899 | + | |
| 3900 | + | |
| 3901 | + | |
| 3902 | + | |
| 3903 | + | |
| 3904 | + | |
| 3905 | + | |
| 3906 | + | |
| 3907 | + | |
| 3908 | + | |
| 3909 | + | |
| 3910 | + | |
| 3911 | + | |
| 3912 | + | |
| 3913 | + | |
| 3914 | + | |
| 3915 | + | |
| 3916 | + | |
| 3917 | + | |
| 3918 | + | |
| 3919 | + | |
| 3920 | + | |
| 3921 | + | |
3885 | 3922 |
| |
3886 | 3923 |
| |
3887 | 3924 |
| |
| |||
4274 | 4311 |
| |
4275 | 4312 |
| |
4276 | 4313 |
| |
4277 |
| - | |
| 4314 | + | |
4278 | 4315 |
| |
4279 | 4316 |
| |
4280 | 4317 |
| |
| |||
4522 | 4559 |
| |
4523 | 4560 |
| |
4524 | 4561 |
| |
| 4562 | + | |
| 4563 | + | |
4525 | 4564 |
| |
4526 | 4565 |
| |
4527 | 4566 |
| |
| |||
4555 | 4594 |
| |
4556 | 4595 |
| |
4557 | 4596 |
| |
| 4597 | + | |
| 4598 | + | |
4558 | 4599 |
| |
4559 | 4600 |
| |
4560 |
| - | |
4561 |
| - | |
4562 |
| - | |
4563 |
| - | |
4564 |
| - | |
4565 |
| - | |
4566 |
| - | |
4567 |
| - | |
4568 | 4601 |
| |
4569 | 4602 |
| |
4570 | 4603 |
| |
| 4604 | + | |
4571 | 4605 |
| |
4572 |
| - | |
4573 |
| - | |
| 4606 | + | |
4574 | 4607 |
| |
| 4608 | + | |
| 4609 | + | |
| 4610 | + | |
| 4611 | + | |
| 4612 | + | |
| 4613 | + | |
| 4614 | + | |
| 4615 | + | |
| 4616 | + | |
| 4617 | + | |
| 4618 | + | |
| 4619 | + | |
| 4620 | + | |
| 4621 | + | |
| 4622 | + | |
| 4623 | + | |
| 4624 | + | |
| 4625 | + | |
| 4626 | + | |
| 4627 | + | |
| 4628 | + | |
| 4629 | + | |
| 4630 | + | |
4575 | 4631 |
| |
4576 | 4632 |
| |
4577 | 4633 |
| |
|
0 commit comments
Comments
(0)