<feed xmlns='http://www.w3.org/2005/Atom'>
<title>postgresql.git/src/include/regex, branch master</title>
<subtitle>This is the main PostgreSQL git repository.</subtitle>
<id>http://git.postgresql.org/cgit/postgresql.git/atom?h=master</id>
<link rel='self' href='http://git.postgresql.org/cgit/postgresql.git/atom?h=master'/>
<link rel='alternate' type='text/html' href='http://git.postgresql.org/cgit/postgresql.git/'/>
<updated>2026-05-11T12:13:46Z</updated>
<entry>
<title>Harden our regex engine against integer overflow in size calculations.</title>
<updated>2026-05-11T12:13:46Z</updated>
<author>
<name>Tom Lane</name>
</author>
<published>2026-05-11T12:13:46Z</published>
<link rel='alternate' type='text/html' href='http://git.postgresql.org/cgit/postgresql.git/commit/?id=0dc1fdc75ebbad9419ac5e313064be0fcf092543'/>
<id>urn:sha1:0dc1fdc75ebbad9419ac5e313064be0fcf092543</id>
<content type='text'>
The number of NFA states, number of NFA arcs, and number of colors
are all bounded to reasonably small values.  However, there are
places where we try to allocate arrays sized by products of those
quantities, and those calculations could overflow, enabling
buffer-overrun attacks.  In practice there's no problem on 64-bit
machines, but there are some live scenarios on 32-bit machines.

A related problem is that citerdissect() and creviterdissect()
allocate arrays based on the length of the input string, which
potentially could overflow.

To fix, invent MALLOC_ARRAY and REALLOC_ARRAY macros that rely on
palloc_array_extended and repalloc_array_extended with the NO_OOM
option, similarly to the existing MALLOC and REALLOC macros.
(Like those, they'll throw an error not return a NULL result for
oversize requests.  This doesn't really fit into the regex code's
view of error handling, but it'll do for now.  We can consider
whether to change that behavior in a non-security follow-up patch.)

I installed similar defenses in the colormap construction code.
It's not entirely clear whether integer overflow is possible
there, but analyzing the behavior in detail seems not worth
the trouble, as the risky spots are not in hot code paths.

I left a bunch of calls as-is after verifying that they can't
overflow given reasonable limits on nstates and narcs.  Those
limits were enforced already via REG_MAX_COMPILE_SPACE, but
add commentary to document the interactions.

In passing, also fix a related edge case, which is that the
special color numbers used in LACON carcs could overflow the
"color" data type, if ncolors is close to MAX_COLOR.

In v14 and v15, the regex engine calls malloc() directly instead
of using palloc(), so MALLOC_ARRAY and REALLOC_ARRAY do likewise.

Reported-by: Xint Code
Author: Tom Lane &lt;tgl@sss.pgh.pa.us&gt;
Reviewed-by: Masahiko Sawada &lt;sawada.mshk@gmail.com&gt;
Backpatch-through: 14
Security: CVE-2026-6473
</content>
</entry>
<entry>
<title>Update copyright for 2026</title>
<updated>2026-01-01T18:24:10Z</updated>
<author>
<name>Bruce Momjian</name>
</author>
<published>2026-01-01T18:24:10Z</published>
<link rel='alternate' type='text/html' href='http://git.postgresql.org/cgit/postgresql.git/commit/?id=451c43974f8e199097d97624a4952ad0973cea61'/>
<id>urn:sha1:451c43974f8e199097d97624a4952ad0973cea61</id>
<content type='text'>
Backpatch-through: 14
</content>
</entry>
<entry>
<title>Make &lt;assert.h&gt; consistently available in frontend and backend</title>
<updated>2025-12-11T08:56:57Z</updated>
<author>
<name>Peter Eisentraut</name>
</author>
<published>2025-12-11T08:19:17Z</published>
<link rel='alternate' type='text/html' href='http://git.postgresql.org/cgit/postgresql.git/commit/?id=795e94c70cf13f60b2cb4010f29a1bca542d2031'/>
<id>urn:sha1:795e94c70cf13f60b2cb4010f29a1bca542d2031</id>
<content type='text'>
Previously, c.h made &lt;assert.h&gt; only available in frontends (#ifdef
FRONTEND), which was probably reasonable, because the only thing it
would give you is assert(), which you generally shouldn't use in the
backend.  But with C11, &lt;assert.h&gt; also makes available
static_assert(), which would be useful everywhere.  So this patch
moves &lt;assert.h&gt; to the commonly available header files in c.h and
fixes a small complication in regcustom.h that resulted from that.

Co-authored-by: Thomas Munro &lt;thomas.munro@gmail.com&gt;
Discussion: https://www.postgresql.org/message-id/flat/CA%2BhUKGKvr0x_oGmQTUkx%3DODgSksT2EtgCA6LmGx_jQFG%3DsDUpg%40mail.gmail.com
</content>
</entry>
<entry>
<title>pg_regc_locale.c: rename some static functions.</title>
<updated>2025-10-14T18:04:04Z</updated>
<author>
<name>Jeff Davis</name>
</author>
<published>2025-10-14T18:04:04Z</published>
<link rel='alternate' type='text/html' href='http://git.postgresql.org/cgit/postgresql.git/commit/?id=8efe982fe2c5b900554d489c0409618638193aef'/>
<id>urn:sha1:8efe982fe2c5b900554d489c0409618638193aef</id>
<content type='text'>
Use the more specific prefix "regc_" rather than the generic prefix
"pg_".

A subsequent commit will create generic versions of some of these
functions that can be called from other modules.

Discussion: https://postgr.es/m/0151ad01239e2cc7b3139644358cf8f7b9622ff7.camel@j-davis.com
</content>
</entry>
<entry>
<title>Update copyright for 2025</title>
<updated>2025-01-01T16:21:55Z</updated>
<author>
<name>Bruce Momjian</name>
</author>
<published>2025-01-01T16:21:55Z</published>
<link rel='alternate' type='text/html' href='http://git.postgresql.org/cgit/postgresql.git/commit/?id=50e6eb731d98ab6d0e625a0b87fb327b172bbebd'/>
<id>urn:sha1:50e6eb731d98ab6d0e625a0b87fb327b172bbebd</id>
<content type='text'>
Backpatch-through: 13
</content>
</entry>
<entry>
<title>Avoid assertion due to disconnected NFA sub-graphs in regex parsing.</title>
<updated>2024-11-15T23:23:38Z</updated>
<author>
<name>Tom Lane</name>
</author>
<published>2024-11-15T23:23:38Z</published>
<link rel='alternate' type='text/html' href='http://git.postgresql.org/cgit/postgresql.git/commit/?id=b69bdcee9c9cfd8550c4e847d035f441fcee7d01'/>
<id>urn:sha1:b69bdcee9c9cfd8550c4e847d035f441fcee7d01</id>
<content type='text'>
In commit 08c0d6ad6 which introduced "rainbow" arcs in regex NFAs,
I didn't think terribly hard about what to do when creating the color
complement of a rainbow arc.  Clearly, the complement cannot match any
characters, and I took the easy way out by just not building any arcs
at all in the complement arc set.  That mostly works, but Nikolay
Shaplov found a case where it doesn't: if we decide to delete that
sub-NFA later because it's inside a "{0}" quantifier, delsub()
suffered an assertion failure.  That's because delsub() relies on
the target sub-NFA being fully connected.  That was always true
before, and the best fix seems to be to restore that property.
Hence, invent a new arc type CANTMATCH that can be generated in
place of an empty color complement, and drop it again later when we
start NFA optimization.  (At that point we don't need to do delsub()
any more, and besides there are other cases where NFA optimization can
lead to disconnected subgraphs.)

It appears that this bug has no consequences in a non-assert-enabled
build: there will be some transiently leaked NFA states/arcs, but
they'll get cleaned up eventually.  Still, we don't like assertion
failures, so back-patch to v14 where rainbow arcs were introduced.

Per bug #18708 from Nikolay Shaplov.

Discussion: https://postgr.es/m/18708-f94f2599c9d2c005@postgresql.org
</content>
</entry>
<entry>
<title>Cope with &lt;regex.h&gt; name clashes.</title>
<updated>2024-07-05T22:27:16Z</updated>
<author>
<name>Thomas Munro</name>
</author>
<published>2024-07-05T22:24:49Z</published>
<link rel='alternate' type='text/html' href='http://git.postgresql.org/cgit/postgresql.git/commit/?id=2a5ef09830401071be64d4eff3f6db421263a880'/>
<id>urn:sha1:2a5ef09830401071be64d4eff3f6db421263a880</id>
<content type='text'>
macOS 15's SDK pulls in headers related to &lt;regex.h&gt; when we include
&lt;xlocale.h&gt;.  This causes our own regex_t implementation to clash with
the OS's regex_t implementation.  Luckily our function names already had
pg_ prefixes, but the macros and typenames did not.

Include &lt;regex.h&gt; explicitly on all POSIX systems, and fix everything
that breaks.  Then we can prove that we are capable of fully hiding and
replacing the system regex API with our own.

1.  Deal with standard-clobbering macros by undefining them all first.
POSIX says they are "symbolic constants".  If they are macros, this
allows us to redefine them.  If they are enums or variables, our macros
will hide them.

2.  Deal with standard-clobbering types by giving our types pg_
prefixes, and then using macros to redirect xxx_t -&gt; pg_xxx_t.

After including our "regex/regex.h", the system &lt;regex.h&gt; is hidden,
because we've replaced all the standard names.  The PostgreSQL source
tree and extensions can continue to use standard prefix-less type and
macro names, but reach our implementation, if they included our
"regex/regex.h" header.

Back-patch to all supported branches, so that macOS 15's tool chain can
build them.

Reported-by: Stan Hu &lt;stanhu@gmail.com&gt;
Suggested-by: Tom Lane &lt;tgl@sss.pgh.pa.us&gt;
Tested-by: Aleksander Alekseev &lt;aleksander@timescale.com&gt;
Discussion: https://postgr.es/m/CAMBWrQnEwEJtgOv7EUNsXmFw2Ub4p5P%2B5QTBEgYwiyjy7rAsEQ%40mail.gmail.com
</content>
</entry>
<entry>
<title>Update copyright for 2024</title>
<updated>2024-01-04T01:49:05Z</updated>
<author>
<name>Bruce Momjian</name>
</author>
<published>2024-01-04T01:49:05Z</published>
<link rel='alternate' type='text/html' href='http://git.postgresql.org/cgit/postgresql.git/commit/?id=29275b1d177096597675b5c6e7e7c9db2df8f4df'/>
<id>urn:sha1:29275b1d177096597675b5c6e7e7c9db2df8f4df</id>
<content type='text'>
Reported-by: Michael Paquier

Discussion: https://postgr.es/m/ZZKTDPxBBMt3C0J9@paquier.xyz

Backpatch-through: 12
</content>
</entry>
<entry>
<title>Fix various typos</title>
<updated>2023-04-18T01:23:23Z</updated>
<author>
<name>David Rowley</name>
</author>
<published>2023-04-18T01:23:23Z</published>
<link rel='alternate' type='text/html' href='http://git.postgresql.org/cgit/postgresql.git/commit/?id=b4dbf3e924b2556acbe103dc61ac71f9985ff24f'/>
<id>urn:sha1:b4dbf3e924b2556acbe103dc61ac71f9985ff24f</id>
<content type='text'>
This fixes many spelling mistakes in comments, but a few references to
invalid parameter names, function names and option names too in comments
and also some in string constants

Also, fix an #undef that was undefining the incorrect definition

Author: Alexander Lakhin
Reviewed-by: Justin Pryzby
Discussion: https://postgr.es/m/d5f68d19-c0fc-91a9-118d-7c6a5a3f5fad@gmail.com
</content>
</entry>
<entry>
<title>Redesign interrupt/cancel API for regex engine.</title>
<updated>2023-04-08T10:10:39Z</updated>
<author>
<name>Thomas Munro</name>
</author>
<published>2023-04-08T09:57:46Z</published>
<link rel='alternate' type='text/html' href='http://git.postgresql.org/cgit/postgresql.git/commit/?id=db4f21e4a34b1d5a3f7123e28e77f575d1a971ea'/>
<id>urn:sha1:db4f21e4a34b1d5a3f7123e28e77f575d1a971ea</id>
<content type='text'>
Previously, a PostgreSQL-specific callback checked by the regex engine
had a way to trigger a special error code REG_CANCEL if it detected that
the next call to CHECK_FOR_INTERRUPTS() would certainly throw via
ereport().

A later proposed bugfix aims to move some complex logic out of signal
handlers, so that it won't run until the next CHECK_FOR_INTERRUPTS(),
which makes the above design impossible unless we split
CHECK_FOR_INTERRUPTS() into two phases, one to run logic and another to
ereport().  We may develop such a system in the future, but for the
regex code it is no longer necessary.

An earlier commit moved regex memory management over to our
MemoryContext system.  Given that the purpose of the two-phase interrupt
checking was to free memory before throwing, something we don't need to
worry about anymore, it seems simpler to inject CHECK_FOR_INTERRUPTS()
directly into cancelation points, and just let it throw.

Since the plan is to keep PostgreSQL-specific concerns separate from the
main regex engine code (with a view to bein able to stay in sync with
other projects), do this with a new macro INTERRUPT(), customizable in
regcustom.h and defaulting to nothing.

Reviewed-by: Tom Lane &lt;tgl@sss.pgh.pa.us&gt;
Discussion: https://postgr.es/m/CA%2BhUKGK3PGKwcKqzoosamn36YW-fsuTdOPPF1i_rtEO%3DnEYKSg%40mail.gmail.com
</content>
</entry>
</feed>
