Fix another ancient bug in parsing of BRE-mode regular expressions.
authorTom Lane <[email protected]>
Fri, 19 Feb 2021 03:38:55 +0000 (22:38 -0500)
committerTom Lane <[email protected]>
Fri, 19 Feb 2021 03:38:55 +0000 (22:38 -0500)
While poking at the regex code, I happened to notice that the bug
squashed in commit afcc8772e had a sibling: next() failed to return
a specific value associated with the '}' token for a "\{m,n\}"
quantifier when parsing in basic RE mode.  Again, this could result
in treating the quantifier as non-greedy, which it never should be in
basic mode.  For that to happen, the last character before "\}" that
sets "nextvalue" would have to set it to zero, or it'd have to have
accidentally been zero from the start.  The failure can be provoked
repeatably with, for example, a bound ending in digit "0".

Like the previous patch, back-patch all the way.

src/backend/regex/regc_lex.c
src/test/modules/test_regex/expected/test_regex.out
src/test/modules/test_regex/sql/test_regex.sql

index ca2bce48312aab1709389eca3a84b87adf6b8b8c..16664531641c8f541ef8f4dfcf33802c5fc3baa8 100644 (file)
@@ -389,7 +389,7 @@ next(struct vars *v)
                    {
                        v->now++;
                        INTOCON(L_BRE);
-                       RET('}');
+                       RETV('}', 1);
                    }
                    else
                        FAILW(REG_BADBR);
index f01ca071d9ba21349c03c6157f673d491d50c286..21282789c2790002a3423fd4db3a1328ad5daec4 100644 (file)
@@ -614,7 +614,7 @@ ERROR:  invalid regular expression: quantifier operand invalid
 -- expectError 7.15 -      a*+ BADRPT
 select * from test_regex('a*+', '', '-');
 ERROR:  invalid regular expression: quantifier operand invalid
--- test for ancient brenext() bug; not currently in Tcl
+-- tests for ancient brenext() bugs; not currently in Tcl
 select * from test_regex('.*b', 'aaabbb', 'b');
  test_regex 
 ------------
@@ -622,6 +622,13 @@ select * from test_regex('.*b', 'aaabbb', 'b');
  {aaabbb}
 (2 rows)
 
+select * from test_regex('.\{1,10\}', 'abcdef', 'bQ');
+   test_regex    
+-----------------
+ {0,REG_UBOUNDS}
+ {abcdef}
+(2 rows)
+
 -- doing 8 "braces"
 -- expectMatch 8.1  NQ     "a{0,1}"    ""  ""
 select * from test_regex('a{0,1}', '', 'NQ');
index ae7d6b43e4af0575dd188a634496a489399daac8..31e947ee9c6f3c0d1366a3a0d0fc31c15eadb83f 100644 (file)
@@ -214,8 +214,9 @@ select * from test_regex('a?*', '', '-');
 select * from test_regex('a+*', '', '-');
 -- expectError 7.15 -      a*+ BADRPT
 select * from test_regex('a*+', '', '-');
--- test for ancient brenext() bug; not currently in Tcl
+-- tests for ancient brenext() bugs; not currently in Tcl
 select * from test_regex('.*b', 'aaabbb', 'b');
+select * from test_regex('.\{1,10\}', 'abcdef', 'bQ');
 
 -- doing 8 "braces"