summaryrefslogtreecommitdiff
path: root/regcomp.c
diff options
context:
space:
mode:
authorKarl Williamson <public@khwilliamson.com>2013-07-01 10:26:14 -0600
committerKarl Williamson <public@khwilliamson.com>2013-07-01 11:02:39 -0600
commit2e3a23da260a7ec5d61b81cb34c38de5e528b41d (patch)
treeb6e1f58162b25d67665f77e6e8e8d2039ce3eb76 /regcomp.c
parent6fb687a82f7642155c104cfe96d6eb6f090ba803 (diff)
downloadperl-2e3a23da260a7ec5d61b81cb34c38de5e528b41d.tar.gz
Fix regex seqfault 5.18 regression
This segfault is a result of an optimization that can leave the compilation in an inconsistent state. /f{0}/ doesn't match anything, and hence should be removable from the regex for all f. However, qr{(?&foo){0}(?<foo>)} caused a segfault. What was happening prior to this commit is that (?&foo) refers to a named capture group further along in the regex. The "{0}" caused the "(?&foo)" to be discarded prior to setting up the pointers between the two related subexpressions; a segfault follows. This commit removes the optimization, and should be suitable for a maintenance release. One might think that no one would be writing code like this, but this example was distilled from machine-generated code in Regexp::Grammars. Perhaps this optimization can be done, but the location I chose for checking it was during parsing, which turns out to be premature. It would be better to do it in the optimization phase of regex compilation. Another option would be to retain it where it was, but for it to operate only on a limited set of nodes, such as EXACTish, which would have no unintended consequences. But that is for looking at in the future; the important thing is to have a simple patch suitable for fixing this regression in a maintenance release. For the record, the code being reverted was mistakenly added by me in commit 3018b823898645e44b8c37c70ac5c6302b031381, and wasn't even mentioned in that commit message. It should have had its own commit.
Diffstat (limited to 'regcomp.c')
-rw-r--r--regcomp.c18
1 files changed, 0 insertions, 18 deletions
diff --git a/regcomp.c b/regcomp.c
index d01f62a5e6..4885c0b5a6 100644
--- a/regcomp.c
+++ b/regcomp.c
@@ -9696,24 +9696,6 @@ S_regpiece(pTHX_ RExC_state_t *pRExC_state, I32 *flagp, U32 depth)
ret = reg_node(pRExC_state, OPFAIL);
return ret;
}
- else if (max == 0) { /* replace {0} with a nothing node */
- if (SIZE_ONLY) {
- RExC_size = PREVOPER(RExC_size) - regarglen[(U8)NOTHING];
- }
- else {
- RExC_emit = orig_emit;
- }
- ret = reg_node(pRExC_state, NOTHING);
-
- /* But the quantifier includes any '?', the non-greedy
- * modifier, after the {}, [perl #118375]
- * Likewise the '+', the possessive modifier. They are mutually exclusive.
- */
- if (RExC_parse < RExC_end && (*RExC_parse == '?' || *RExC_parse == '+') ) {
- nextchar(pRExC_state);
- }
- return ret;
- }
do_curly:
if ((flags&SIMPLE)) {