]> git.ipfire.org Git - thirdparty/postgresql.git/commit
Fix ancient bug in parsing of BRE-mode regular expressions.
authorTom Lane <tgl@sss.pgh.pa.us>
Fri, 8 Jan 2021 17:16:00 +0000 (12:16 -0500)
committerTom Lane <tgl@sss.pgh.pa.us>
Fri, 8 Jan 2021 17:16:00 +0000 (12:16 -0500)
commit769908811b8b7ea7a087d5a016b9e94042f89481
tree0b17069b41f02002ab6009d42436fabb59429ba2
parentc67fea09da25463b6f6fc73fa2676ffd53e9a8e5
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
src/backend/regex/regc_lex.c