Re: Segmentation fault during update inside ExecBRUpdateTriggers
Thomas Munro <thomas.munro@gmail.com>
From: Thomas Munro <thomas.munro@gmail.com>
To: Piotr Gabriel Kosinski <pg.kosinski@gmail.com>
Cc: PostgreSQL mailing lists <pgsql-bugs@lists.postgresql.org>
Date: 2019-08-15T22:23:15Z
Lists: pgsql-bugs
On Fri, Aug 16, 2019 at 9:55 AM Piotr Gabriel Kosinski
<pg.kosinski@gmail.com> wrote:
> Backtrace on Debian Buster:
>
> #0 0x000055c9e358b0c0 in ?? ()
> #1 0x000055c9e133d144 in ExecBRUpdateTriggers
> (estate=estate@entry=0x55c9e3583190,
> epqstate=epqstate@entry=0x55c9e35845c0,
> relinfo=relinfo@entry=0x55c9e3583420,
> tupleid=tupleid@entry=0x7fff0e1565da,
> fdw_trigtuple=fdw_trigtuple@entry=0x0, slot=0x55c9e3589688) at
> ./build/../src/backend/commands/trigger.c:3065
Hi,
Right, this happens on REL_11_STABLE but not on master (which rewrote
the relevant code quite a bit in the "slotification" project). It's a
double free, here:
for (i = 0; i < trigdesc->numtriggers; i++)
{
...
if (oldtuple != newtuple && oldtuple != slottuple)
heap_freetuple(oldtuple);
...
}
if (trigtuple != fdw_trigtuple && trigtuple != newtuple)
heap_freetuple(trigtuple);
In a very quick test, the following change fixes the problem and
passes regression tests, but I'm not sure if it's the right fix.
- if (oldtuple != newtuple && oldtuple != slottuple)
+ if (oldtuple != newtuple && oldtuple != slottuple &&
oldtuple != trigtuple)
--
Thomas Munro
https://enterprisedb.com
Commits
-
Prevent possible double-free when update trigger returns old tuple.
- cb0c79ae6231 9.5.20 landed
- afa71d9152a2 9.4.25 landed
- aed967d697de 11.6 landed
- 60886965a271 10.11 landed
- 1fe8d209ed84 9.6.16 landed
- 1ced082b95b3 13.0 landed
- 03813a50efa5 12.0 landed
-
Prevent dangling-pointer access when update trigger returns old tuple.
- 25b692568f42 11.0 cited