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: Fix ancient bug in parsing of BRE-mode regular expressions.
Date: Fri, 08 Jan 2021 17:16:20 +0000
Message-ID: <E1kxvN6-0002xJ-4Q@gemulon.postgresql.org> (raw)

Fix ancient bug in parsing of BRE-mode regular expressions.

brenext(), when parsing a '*' quantifier, forgot to return any "value"
for the token; per the equivalent case in next(), it should return
value 1 to indicate that greedy rather than non-greedy behavior is
wanted.  The result is that the compiled regexp could behave like 'x*?'
rather than the intended 'x*', if we were unlucky enough to have
a zero in v->nextvalue at this point.  That seems to happen with some
reliability if we have '.*' at the beginning of a BRE-mode regexp,
although that depends on the initial contents of a stack-allocated
struct, so it's not guaranteed to fail.

Found by Alexander Lakhin using valgrind testing.  This bug seems
to be aboriginal in Spencer's code, so back-patch all the way.

Discussion: https://postgr.es/m/16814-6c5e3edd2bdf0d50@postgresql.org

Branch
------
REL_10_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/2d540ac5f1f340931b6b1055240ed6c0e258d447

Modified Files
--------------
src/backend/regex/regc_lex.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)



view thread (7+ messages)  latest in thread

Message-ID: <E1kxvN6-0002xJ-4Q@gemulon.postgresql.org>
Permalink:  ../E1kxvN6-0002xJ-4Q@gemulon.postgresql.org/
Also on:    postgresql.org/message-id/E1kxvN6-0002xJ-4Q@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: Fix ancient bug in parsing of BRE-mode regular expressions.
  In-Reply-To: <E1kxvN6-0002xJ-4Q@gemulon.postgresql.org>
  References: <E1kxvN6-0002xJ-4Q@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