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: Avoid crash after function syntax error in a replication worker.
Date: Thu, 03 Nov 2022 16:02:25 +0000
Message-ID: <E1oqcfi-000GzJ-0y@gemulon.postgresql.org> (raw)

Avoid crash after function syntax error in a replication worker.

If a syntax error occurred in a SQL-language or PL/pgSQL-language
CREATE FUNCTION or DO command executed in a logical replication worker,
we'd suffer a null pointer dereference or assertion failure.  That
seems like a rather contrived case, but nonetheless worth fixing.

The cause is that function_parse_error_transpose assumes it must be
executing within the context of a Portal, but logical/worker.c
doesn't create a Portal since it's not running the standard executor.
We can just back off the hard Assert check and make it fail gracefully
if there's not an ActivePortal.  (I have a feeling that the aggressive
check here was my fault originally, probably because I wasn't sure if
the case would always hold and wanted to find out.  Well, now we know.)

The hazard seems to exist in all branches that have logical replication,
so back-patch to v10.

Maxim Orlov, Anton Melnikov, Masahiko Sawada, Tom Lane

Discussion: https://postgr.es/m/b570c367-ba38-95f3-f62d-5f59b9808226@inbox.ru
Discussion: https://postgr.es/m/adf0452f-8c6b-7def-d35e-ab516c80088e@inbox.ru

Branch
------
REL_14_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/2489c38cdc58bdd2f181651e741440bb6b83e80b

Modified Files
--------------
src/backend/catalog/pg_proc.c | 20 +++++++++++++++-----
1 file changed, 15 insertions(+), 5 deletions(-)



view thread (7+ messages)

Message-ID: <E1oqcfi-000GzJ-0y@gemulon.postgresql.org>
Permalink:  ../E1oqcfi-000GzJ-0y@gemulon.postgresql.org/
Also on:    postgresql.org/message-id/E1oqcfi-000GzJ-0y@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: Avoid crash after function syntax error in a replication worker.
  In-Reply-To: <E1oqcfi-000GzJ-0y@gemulon.postgresql.org>
  References: <E1oqcfi-000GzJ-0y@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