forked frompostgres/postgres
- Notifications
You must be signed in to change notification settings - Fork6
Commit25b6925
committed
Prevent dangling-pointer access when update trigger returns old tuple.
A before-update row trigger may choose to return the "new" or "old" tupleunmodified. ExecBRUpdateTriggers failed to consider the secondpossibility, and would proceed to free the "old" tuple even if it was theone returned, leading to subsequent access to already-deallocated memory.In debug builds this reliably leads to an "invalid memory alloc requestsize" failure; in production builds it might accidentally work, but datacorruption is also possible.This is a very old bug. There are probably a couple of reasons it hasn'tbeen noticed up to now. It would be more usual to return NULL if onewanted to suppress the update action; returning "old" is significantly lessefficient since the update will occur anyway. Also, none of the standardPLs would ever cause this because they all returned freshly-manufacturedtuples even if they were just copying "old". But commit4b93f57 changedthat for plpgsql, making it possible to see the bug with a plpgsql trigger.Still, this is certainly legal behavior for a trigger function, so it'sExecBRUpdateTriggers's fault not plpgsql's.It seems worth creating a test case that exercises returning "old" directlywith a C-language trigger; testing this through plpgsql seems unreliablebecause its behavior might change again.Report and fix by Rushabh Lathia; regression test case by me.Back-patch to all supported branches.Discussion:https://postgr.es/m/CAGPqQf1P4pjiNPrMof=P_16E-DFjt457j+nH2ex3=nBTew7tXw@mail.gmail.com1 parent5e6a63c commit25b6925
File tree
6 files changed
+67
-1
lines changed- src
- backend/commands
- test/regress
- expected
- input
- output
- sql
6 files changed
+67
-1
lines changedLines changed: 1 addition & 1 deletion
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
2815 | 2815 |
| |
2816 | 2816 |
| |
2817 | 2817 |
| |
2818 |
| - | |
| 2818 | + | |
2819 | 2819 |
| |
2820 | 2820 |
| |
2821 | 2821 |
| |
|
Lines changed: 26 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
119 | 119 |
| |
120 | 120 |
| |
121 | 121 |
| |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
122 | 148 |
| |
123 | 149 |
| |
124 | 150 |
| |
|
Lines changed: 5 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
37 | 37 |
| |
38 | 38 |
| |
39 | 39 |
| |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
40 | 45 |
| |
41 | 46 |
| |
42 | 47 |
| |
|
Lines changed: 4 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
35 | 35 |
| |
36 | 36 |
| |
37 | 37 |
| |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
38 | 42 |
| |
39 | 43 |
| |
40 | 44 |
| |
|
Lines changed: 15 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
203 | 203 |
| |
204 | 204 |
| |
205 | 205 |
| |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
206 | 221 |
| |
207 | 222 |
| |
208 | 223 |
| |
|
Lines changed: 16 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
103 | 103 |
| |
104 | 104 |
| |
105 | 105 |
| |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
106 | 122 |
| |
107 | 123 |
| |
108 | 124 |
| |
|
0 commit comments
Comments
(0)