postgresql/src/backend
Tom Lane d9ffccf8db 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
2022-11-03 12:01:57 -04:00
..
access Fix ordering issue with WAL operations in GIN fast insert path 2022-10-26 09:41:26 +09:00
bootstrap Revert "Skip WAL for new relfilenodes, under wal_level=minimal." 2020-03-22 09:24:13 -07:00
catalog Avoid crash after function syntax error in a replication worker. 2022-11-03 12:01:57 -04:00
commands Fix self-referencing foreign keys with partitioned tables 2022-10-07 19:37:48 +02:00
executor Fix copy-and-pasteo in comment. 2022-11-02 18:15:06 +09:00
foreign Update copyright for 2019 2019-01-02 12:44:25 -05:00
jit Track LLVM 15 changes. 2022-10-19 22:44:53 +13:00
lib Fix lock assertions in dshash.c. 2022-07-11 15:51:47 +12:00
libpq Remove misguided SSL key file ownership check in libpq. 2022-05-26 14:14:05 -04:00
main Fix outdated --help message for postgres -f 2022-08-15 13:37:42 +09:00
nodes Further fixes for MULTIEXPR_SUBLINK fix. 2022-09-06 16:38:18 -04:00
optimizer Guard against table-AM-less relations in planner. 2022-10-17 11:35:23 -04:00
parser Rename parser token REF to REF_P to avoid a symbol conflict. 2022-10-16 15:27:04 -04:00
partitioning Avoid using ambiguous word "non-negative" in error messages. 2021-07-28 01:24:24 +09:00
po Translation updates 2022-08-08 12:39:52 +02:00
port Reject huge_pages=on if shared_memory_type=sysv. 2021-10-26 13:01:52 +13:00
postmaster Prevent long-term memory leakage in autovacuum launcher. 2022-08-31 16:23:20 -04:00
regex Defend against stack overrun in a few more places. 2022-08-24 13:01:40 -04:00
replication Add CHECK_FOR_INTERRUPTS while restoring changes during decoding. 2022-10-21 12:10:11 +05:30
rewrite Reject non-ON-SELECT rules that are named "_RETURN". 2022-10-17 12:14:39 -04:00
snowball In the Snowball dictionary, don't try to stem excessively-long words. 2022-08-31 10:42:05 -04:00
statistics Build inherited extended stats on partitioned tables 2022-01-15 19:02:58 +01:00
storage Harden pmsignal.c against clobbered shared memory. 2022-10-11 18:54:31 -04:00
tcop Force immediate commit after CREATE DATABASE etc in extended protocol. 2022-07-26 13:07:03 -04:00
tsearch Defend against stack overrun in a few more places. 2022-08-24 13:01:40 -04:00
utils Change some errdetail() to errdetail_internal() 2022-09-28 17:14:53 +02:00
.gitignore Add .gitignore entries for AIX-specific intermediate build artifacts. 2015-07-08 20:44:22 -04:00
common.mk Remove PARTIAL_LINKING build mode. 2018-03-30 17:33:04 -07:00
Makefile Get rid of jsonpath_gram.h and jsonpath_scanner.h 2019-03-20 11:13:34 +03:00
nls.mk Translation updates 2020-08-10 15:21:18 +02:00