Fix [perl #115050] Double empty sub-regexp makes "panic!"
authorYves Orton <demerphq@gmail.com>
Sun, 30 Sep 2012 23:01:26 +0000 (01:01 +0200)
committerYves Orton <demerphq@gmail.com>
Sun, 30 Sep 2012 23:24:31 +0000 (01:24 +0200)
Code failed to check if we had a non-zero (END) trietype, and
thus under certain circumstances would panic. We now check that
the trietype is non-zero.

regcomp.c
t/re/pat_rt_report.t

index 9d4fa71..330ab8e 100644 (file)
--- a/regcomp.c
+++ b/regcomp.c
@@ -3425,7 +3425,7 @@ S_study_chunk(pTHX_ RExC_state_t *pRExC_state, regnode **scanp,
                                      * trietype so we can turn them into a trie. If/when we
                                      * allow NOTHING to start a trie sequence this condition will be
                                      * required, and it isn't expensive so we leave it in for now. */
-                                    if ( trietype != NOTHING )
+                                    if ( trietype && trietype != NOTHING )
                                         make_trie( pRExC_state,
                                                 startbranch, first, cur, tail, count,
                                                 trietype, depth+1 );
@@ -3456,7 +3456,7 @@ S_study_chunk(pTHX_ RExC_state_t *pRExC_state, regnode **scanp,
                               "", SvPV_nolen_const( mysv ),REG_NODE_NUM(cur));
 
                         });
-                        if ( last ) {
+                        if ( last && trietype ) {
                             if ( trietype != NOTHING ) {
                                 /* the last branch of the sequence was part of a trie,
                                  * so we have to construct it here outside of the loop
index 3d14414..453e5ab 100644 (file)
@@ -22,7 +22,7 @@ BEGIN {
 }
 
 
-plan tests => 2521;  # Update this when adding/deleting tests.
+plan tests => 2525;  # Update this when adding/deleting tests.
 
 run_tests() unless caller;
 
@@ -1128,6 +1128,17 @@ $t =~ s/([^a])//ge;
 EOP
     }
 
+    {
+        # pattern must be compiled late or we can break the test file
+        my $message = '[perl #115050] repeated nothings in a trie can cause panic';
+        my $pattern;
+        $pattern = '[xyz]|||';
+        ok("blah blah" =~ /$pattern/, $message);
+        ok("blah blah" =~ /(?:$pattern)h/, $message);
+        $pattern = '|||[xyz]';
+        ok("blah blah" =~ /$pattern/, $message);
+        ok("blah blah" =~ /(?:$pattern)h/, $message);
+    }
 } # End of sub run_tests
 
 1;