Skip to content
Tcl Source Code View Ticket
Login

View Ticket

2021-01-11
11:56 • Closed ticket [1dab713a38]: Uninitialized-variable use while parsing '*'... artifact: 0ff076b3c0 user: jan.nijtmans
11:41
Fix [1dab713a38]: Uninitialized-variable use while parsing '*' in BRE-mode regexps check-in: a2ea227d7b user: jan.nijtmans tags: core-8-6-branch
11:39
Fix [1dab713a38]: Uninitialized-variable use while parsing '*' in BRE-mode regexps check-in: 88bf40aa59 user: jan.nijtmans tags: core-8-5-branch
2021-01-08
18:10 • New ticket [1dab713a38] Uninitialized-variable use while parsing '*' in ... artifact: f067701563 user: tgl

Uninitialized-variable use while parsing '*' in BRE-mode regexps

Closed / Fixed1dab713a3808489ef0a23be683b3d2058fbd3f27Created 6 years agoUpdated 6 years ago
Descriptionplain2021-01-08 18:10:46
brenext(), when parsing a '*' quantifier, forgets 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 are unlucky enough to have
a zero in v->nextvalue at this point.  In Postgres it seems not too hard
for that to happen when the regexp begins with, say, '.*'; and in any case
valgrind complains about uninitialized-value usage.  I've had a much
harder time reproducing it in Tcl, but one way that seems reliable is

$ tclsh
% regexp -inline {\u0000} {}
% regexp -inline {(?b).*} {abc}
{}

Of course the correct answer is "abc", and that is what you get (usually)
if you do nothing, or some other regexp, before the buggy one.

The fix is a one-liner:

--- generic/regc_lex.c~ 2019-08-28 08:46:06.000000000 -0400
+++ generic/regc_lex.c  2021-01-08 12:57:11.056650507 -0500
@@ -1005,7 +1005,7 @@ brenext(
        if (LASTTYPE(EMPTY) || LASTTYPE('(') || LASTTYPE('^')) {
            RETV(PLAIN, c);
        }
-       RET('*');
+       RETV('*', 1);
        break;
     case CHR('['):
        if (HAVE(6) &&  *(v->now+0) == CHR('[') &&
Referenced by2
  • a2ea227d7bFix [1dab713a38]: Uninitialized-variable use while parsing '*' in BRE-mode regexps check-in2021-01-11 11:41:54
  • 88bf40aa59Fix [1dab713a38]: Uninitialized-variable use while parsing '*' in BRE-mode regexps check-in2021-01-11 11:39:12
jan.nijtmanswiki2021-01-11 11:56:44

Yes, I can reproduce this. Thanks for the report and fix! Now merged to all active branches.

Log in (anonymous is fine) to add a comment.