postgresql/src
Tom Lane 5d6c64d290 Avoid crashing when a JIT-inlined backend function throws an error.
errfinish() assumes that the __FUNC__ and __FILE__ arguments it's
passed are compile-time constant strings that can just be pointed
to rather than physically copied.  However, it's possible for LLVM
to generate code in which those pointers point into a dynamically
loaded code segment.  If that segment gets unloaded before we're
done with the ErrorData struct, we have dangling pointers that
will lead to SIGSEGV.  In simple cases that won't happen, because we
won't unload LLVM code before end of transaction.  But it's possible
to happen if the error is thrown within end-of-transaction code run by
_SPI_commit or _SPI_rollback, because since commit 2e517818f those
functions clean up by ending the transaction and starting a new one.

Rather than fixing this by adding pstrdup() overhead to every
elog/ereport sequence, let's fix it by copying the risky pointers
in CopyErrorData().  That solves it for _SPI_commit/_SPI_rollback
because they use that function to preserve the error data across
the transaction end/restart sequence; and it seems likely that
any other code doing something similar would need to do that too.

I'm suspicious that this behavior amounts to an LLVM bug (or a
bug in our use of it?), because it implies that string constant
references that should be pointer-equal according to a naive
understanding of C semantics will sometimes not be equal.
However, even if it is a bug and someday gets fixed, we'll have
to cope with the current behavior for a long time to come.

Report and patch by me.  Back-patch to all supported branches.

Discussion: https://postgr.es/m/1565654.1719425368@sss.pgh.pa.us
2024-06-27 14:44:02 -04:00
..
backend Avoid crashing when a JIT-inlined backend function throws an error. 2024-06-27 14:44:02 -04:00
bin Translation updates 2024-06-24 13:11:27 +02:00
common parse_manifest: Use const char * 2024-06-21 07:53:30 +02:00
fe_utils Fix PL/pgSQL's handling of integer ranges containing underscores. 2024-06-04 11:48:01 +01:00
include Fix MVCC bug with prepared xact with subxacts on standby 2024-06-27 21:09:58 +03:00
interfaces Use PqMsg_* macros in fe-auth.c. 2024-06-26 11:25:38 -05:00
makefiles Optimize pg_popcount() with AVX-512 instructions. 2024-04-06 21:56:23 -05:00
pl Translation updates 2024-06-24 13:11:27 +02:00
port Pre-beta mechanical code beautification. 2024-05-14 16:34:50 -04:00
template
test Fix MVCC bug with prepared xact with subxacts on standby 2024-06-27 21:09:58 +03:00
timezone
tools Fix MVCC bug with prepared xact with subxacts on standby 2024-06-27 21:09:58 +03:00
tutorial
.gitignore
DEVELOPERS
Makefile
Makefile.global.in Update Unicode data to CLDR 45 2024-04-22 09:16:33 +02:00
Makefile.shlib
meson.build
nls-global.mk