diff options
author | Hugo van der Sanden <hv@crypt.org> | 2020-09-15 14:02:54 +0100 |
---|---|---|
committer | Steve Hay <steve.m.hay@googlemail.com> | 2020-12-26 15:19:32 +0000 |
commit | 93116e04a61093a3b50ec875085000aff62a2ca9 (patch) | |
tree | 586f73090f32ca7e6979d85fdaf55e4df77f6df2 | |
parent | 9e9893534814fa6362ae99273d3afbf1402502f9 (diff) | |
download | perl-93116e04a61093a3b50ec875085000aff62a2ca9.tar.gz |
[gh18096] assume worst-case for GOSUBs we don't analyse
During study_chunk, under various conditions we avoid recursing into
a GOSUB. But we must avoid giving the enclosing scope the idea that
this GOSUB would match only an empty string, since that could trigger
wrong optimizations (eg CURLYX => CURLYM in the ticket).
So we mark the construct as infinite, as in the code branch where we
_do_ recurse into it.
(cherry picked from commit f4cd5e29bc15621f2ab8fc5d7de0e68e62d43999)
-rw-r--r-- | regcomp.c | 7 | ||||
-rw-r--r-- | t/re/re_tests | 2 |
2 files changed, 8 insertions, 1 deletions
@@ -5224,7 +5224,12 @@ S_study_chunk(pTHX_ RExC_state_t *pRExC_state, regnode **scanp, * might result in a minlen of 1 and not of 4, * but this doesn't make us mismatch, just try a bit * harder than we should. - * */ + * + * However we must assume this GOSUB is infinite, to + * avoid wrongly applying other optimizations in the + * enclosing scope - see GH 18096, for example. + */ + is_inf = is_inf_internal = 1; scan= regnext(scan); continue; } diff --git a/t/re/re_tests b/t/re/re_tests index 9304bd78b1..c6f73d805b 100644 --- a/t/re/re_tests +++ b/t/re/re_tests @@ -2023,6 +2023,8 @@ AB\s+\x{100} AB \x{100}X y - - /(?iaax:A? \K +)/ African_Feh c - \\K + is forbidden - matches null string many times in regex /(?iaa:A?\K+)/ African_Feh c - \\K+ is forbidden - matches null string many times in regex /(?iaa:A?\K*)/ African_Feh c - \\K* is forbidden - matches null string many times in regex +^((\w|<(\s)*(?1)(?3)*>)(?:(?3)*\+(?3)*(?2))*)(?3)*\+ a + b + <c + d> y $1 a + b # [GH #18096] +^((\w|<(\s)*(?1)(?3)*>)(?:(?3)*\+(?3)*(?2))*)(?3)*\+ a + <b> + c y $1 a + <b> # [GH #18096] # Keep these lines at the end of the file # pat string y/n/etc expr expected-expr skip-reason comment # vim: softtabstop=0 noexpandtab |