pg.ddx.io  pgsql-committers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: pgsql-committers@lists.postgresql.org
Subject: pgsql: Prevent possible double-free when update trigger returns old tup
Date: Fri, 16 Aug 2019 00:05:03 +0000
Message-ID: <E1hyPjr-00062u-AH@gemulon.postgresql.org> (raw)

Prevent possible double-free when update trigger returns old tuple.

This is a variant of the problem fixed in commit 25b692568, which
unfortunately we failed to detect at the time.  If an update trigger
returns the "old" tuple, as it's entitled to do, then a subsequent
iteration of the loop in ExecBRUpdateTriggers would have "oldtuple"
equal to "trigtuple" and would fail to notice that it shouldn't
free that.

In addition to fixing the code, extend the test case added by
25b692568 so that it covers multiple-trigger-iterations cases.

This problem does not manifest in v12/HEAD, as a result of the
relevant code having been largely rewritten for slotification.
However, include the test case into v12/HEAD anyway, since this
is clearly an area that someone could break again in future.

Per report from Piotr Gabriel Kosinski.  Back-patch into all
supported branches, since the bug seems quite old.

Diagnosis and code fix by Thomas Munro, test case by me.

Discussion: https://postgr.es/m/CAFMLSdP0rd7LqC3j-H6Fh51FYSt5A10DDh-3=W4PPc4LLUQ8YQ@mail.gmail.com

Branch
------
REL_10_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/60886965a271242c19e40483c82b41ff726ca24e

Modified Files
--------------
src/backend/commands/trigger.c         |  4 +-
src/test/regress/expected/triggers.out | 70 ++++++++++++++++++++++++++++++++++
src/test/regress/sql/triggers.sql      | 35 +++++++++++++++++
3 files changed, 108 insertions(+), 1 deletion(-)



view thread (7+ messages)

Message-ID: <E1hyPjr-00062u-AH@gemulon.postgresql.org>
Permalink:  ../E1hyPjr-00062u-AH@gemulon.postgresql.org/
Also on:    postgresql.org/message-id/E1hyPjr-00062u-AH@gemulon.postgresql.org

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-committers@postgresql.org
  Cc: tgl@sss.pgh.pa.us
  Subject: Re: pgsql: Prevent possible double-free when update trigger returns old tup
  In-Reply-To: <E1hyPjr-00062u-AH@gemulon.postgresql.org>
  References: <E1hyPjr-00062u-AH@gemulon.postgresql.org>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox