Skip to content

Commit 57ddea3

Browse files
committed
Fix regex match failures for backrefs combined with non-greedy quantifiers.
An ancient logic error in cfindloop() could cause the regex engine to fail to find matches that begin later than the start of the string. This function is only used when the regex pattern contains a back reference, and so far as we can tell the error is only reachable if the pattern is non-greedy (i.e. its first quantifier uses the ? modifier). Furthermore, the actual match must begin after some potential match that satisfies the DFA but then fails the back-reference's match test. Reported and fixed by Jeevan Chalke, with cosmetic adjustments by me.
1 parent 4285fb9 commit 57ddea3

File tree

1 file changed

+11
-9
lines changed

1 file changed

+11
-9
lines changed

src/backend/regex/regexec.c

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -464,19 +464,21 @@ cfindloop(struct vars * v,
464464
*coldp = cold;
465465
return er;
466466
}
467-
if ((shorter) ? end == estop : end == begin)
468-
{
469-
/* no point in trying again */
470-
*coldp = cold;
471-
return REG_NOMATCH;
472-
}
473-
/* go around and try again */
467+
/* try next shorter/longer match with same begin point */
474468
if (shorter)
469+
{
470+
if (end == estop)
471+
break; /* NOTE BREAK OUT */
475472
estart = end + 1;
473+
}
476474
else
475+
{
476+
if (end == begin)
477+
break; /* NOTE BREAK OUT */
477478
estop = end - 1;
478-
}
479-
}
479+
}
480+
} /* end loop over endpoint positions */
481+
} /* end loop over beginning positions */
480482
} while (close < v->stop);
481483

482484
*coldp = cold;

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy