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: Fix confusion about event trigger vs. plain function in plpgsql.
Date: Wed, 19 Feb 2020 19:45:30 +0000
Message-ID: <E1j4VHm-0004IA-VT@gemulon.postgresql.org> (raw)

Fix confusion about event trigger vs. plain function in plpgsql.

The function hash table keys made by compute_function_hashkey() failed
to distinguish event-trigger call context from regular call context.
This meant that once we'd successfully made a hash entry for an event
trigger (either by validation, or by normal use as an event trigger),
an attempt to call the trigger function as a plain function would
find this hash entry and thereby bypass the you-can't-do-that check in
do_compile().  Thus we'd attempt to execute the function, leading to
strange errors or even crashes, depending on function contents and
server version.

To fix, add an isEventTrigger field to PLpgSQL_func_hashkey,
paralleling the longstanding infrastructure for regular triggers.
This fits into what had been pad space, so there's no risk of an ABI
break, even assuming that any third-party code is looking at these
hash keys.  (I considered replacing isTrigger with a PLpgSQL_trigtype
enum field, but felt that that carried some API/ABI risk.  Maybe we
should change it in HEAD though.)

Per bug #16266 from Alexander Lakhin.  This has been broken since
event triggers were invented, so back-patch to all supported branches.

Discussion: https://postgr.es/m/16266-fcd7f838e97ba5d4@postgresql.org

Branch
------
REL_12_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/32aa14d40c7ce12e648c9f88fe22fa0146bee3b4

Modified Files
--------------
src/pl/plpgsql/src/pl_comp.c                | 15 +++++++++++----
src/pl/plpgsql/src/plpgsql.h                |  5 +++--
src/test/regress/expected/event_trigger.out |  4 ++++
src/test/regress/sql/event_trigger.sql      |  3 +++
4 files changed, 21 insertions(+), 6 deletions(-)



view thread (6+ messages)  latest in thread

Message-ID: <E1j4VHm-0004IA-VT@gemulon.postgresql.org>
Permalink:  ../E1j4VHm-0004IA-VT@gemulon.postgresql.org/
Also on:    postgresql.org/message-id/E1j4VHm-0004IA-VT@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: Fix confusion about event trigger vs. plain function in plpgsql.
  In-Reply-To: <E1j4VHm-0004IA-VT@gemulon.postgresql.org>
  References: <E1j4VHm-0004IA-VT@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