postgresql/src
Tom Lane df1a2633b1 Fix recently-exposed portability issue in regex optimization.
fixempties() counts the number of in-arcs in the regex NFA and then
allocates an array of that many arc pointers.  If the NFA contains no
arcs, this amounts to malloc(0) for which some platforms return NULL.
The code mistakenly treats that as indicating out-of-memory.  Thus,
we can get a bogus "out of memory" failure for some unsatisfiable
regexes.

This happens only in v15 and earlier, since bea3d7e38 switched to
using palloc() rather than bare malloc().  And at least of the
platforms in the buildfarm, only AIX seems to return NULL.  So the
impact is pretty narrow.  But I don't especially want to ship code
that is failing its own regression tests, so let's fix this for
this week's releases.

A quick code survey says that there is only the one place in
src/backend/regex/ that is at risk of doing malloc(0), so we'll just
band-aid that place.  A more future-proof fix could be to install a
malloc() wrapper similar to pg_malloc().  But this code seems unlikely
to change much more in the affected branches, so that's probably
overkill.

The only known test case for this involves a complemented character
class in a bracket expression, for example [^\s\S], and we didn't
support that in v13.  So it may be that the problem is unreachable
in v13.  But I'm not 100% sure of that, so patch v13 too.

Discussion: https://postgr.es/m/661fd81b-f069-8f30-1a41-e195c57449b4@gmail.com
2024-11-17 14:14:06 -05:00
..
backend Fix recently-exposed portability issue in regex optimization. 2024-11-17 14:14:06 -05:00
bin Avoid deleting critical WAL segments during pg_rewind 2024-11-15 12:53:12 +01:00
common Replace pgwin32_is_junction() with lstat(). 2024-11-08 09:36:53 +10:30
fe_utils Don't spuriously report FD_SETSIZE exhaustion on Windows. 2023-10-14 15:54:49 -07:00
include Undo unintentional ABI break in struct ResultRelInfo. 2024-11-16 12:58:26 -05:00
interfaces Translation updates 2024-11-11 13:57:37 +01:00
makefiles Add NO_INSTALL option to pgxs 2021-05-27 13:58:29 +02:00
pl Fix cross-version upgrade tests. 2024-11-11 13:57:41 -05:00
port Replace pgwin32_is_junction() with lstat(). 2024-11-08 09:36:53 +10:30
template On NetBSD, force dynamic symbol resolution at postmaster start. 2022-08-30 17:29:03 -04:00
test Fix per-session activation of ALTER {ROLE|DATABASE} SET role. 2024-11-15 20:40:00 -08:00
timezone Update time zone data files to tzdata release 2024b. 2024-10-29 11:50:05 -04:00
tools Avoid deleting critical WAL segments during pg_rewind 2024-11-15 12:53:12 +01:00
tutorial Doc: sync src/tutorial/basics.source with SGML documentation. 2022-11-19 13:09:14 -05:00
.gitignore
DEVELOPERS
Makefile Remove the option to build thread_test.c outside configure. 2020-10-21 12:08:48 -04:00
Makefile.global.in Suppress macOS warnings about duplicate libraries in link commands. 2023-09-29 14:07:30 -04:00
Makefile.shlib Stop using "-multiply_defined suppress" on macOS. 2023-09-26 21:06:21 -04:00
nls-global.mk Add errhint_plural() function and make use of it 2021-03-31 09:16:25 +02:00