pg.ddx.io  pgsql-committers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Andres Freund <andres@anarazel.de>
To: pgsql-committers@lists.postgresql.org
Subject: pgsql: Fix crash caused by EPQ happening with a before update trigger p
Date: Fri, 04 Oct 2019 21:36:58 +0000
Message-ID: <E1iGVFy-0001Jb-GT@gemulon.postgresql.org> (raw)

Fix crash caused by EPQ happening with a before update trigger present.

When ExecBRUpdateTriggers()'s GetTupleForTrigger() follows an EPQ
chain the former needs to run the result tuple through the junkfilter
again, and update the slot containing the new version of the tuple to
contain that new version. The input tuple may already be in the
junkfilter's output slot, which used to be OK - we don't need the
previous version anymore. Unfortunately ff11e7f4b9ae started to use
ExecCopySlot() to update newslot, and ExecCopySlot() doesn't support
copying a slot into itself, leading to a slot in a corrupt
state, which then can cause crashes or other symptoms.

Fix this by skipping the ExecCopySlot() when copying into itself.

While we could have easily made ExecCopySlot() handle that case, it
seems better to add an assert forbidding doing so instead. As the goal
of copying might be to make the contents of one slot independent from
another, it seems failure prone to handle doing so silently.

A follow-up commit will add tests for the obviously under-covered
combination of EPQ and triggers. Done as a separate commit as it might
make sense to backpatch them further than this bug.

Also remove confusion with confusing variable names for slots in
ExecBRDeleteTriggers() and ExecBRUpdateTriggers().

Bug: #16036
Reported-By: Антон Власов
Author: Andres Freund
Discussion: https://postgr.es/m/16036-28184c90d952fb7f@postgresql.org
Backpatch: 12-, where ff11e7f4b9ae was merged

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/d986d4e87f61c68f52c68ebc274960dc664b7b4e

Modified Files
--------------
src/backend/commands/trigger.c  | 44 +++++++++++++++++++++--------------------
src/include/executor/tuptable.h |  1 +
2 files changed, 24 insertions(+), 21 deletions(-)



view thread (2+ messages)  latest in thread

Message-ID: <E1iGVFy-0001Jb-GT@gemulon.postgresql.org>
Permalink:  ../E1iGVFy-0001Jb-GT@gemulon.postgresql.org/
Also on:    postgresql.org/message-id/E1iGVFy-0001Jb-GT@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: andres@anarazel.de
  Subject: Re: pgsql: Fix crash caused by EPQ happening with a before update trigger p
  In-Reply-To: <E1iGVFy-0001Jb-GT@gemulon.postgresql.org>
  References: <E1iGVFy-0001Jb-GT@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