This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
PATCH: [perl #127599] Fix regcomp.c assertion
authorKarl Williamson <khw@cpan.org>
Wed, 2 Mar 2016 17:50:01 +0000 (10:50 -0700)
committerKarl Williamson <khw@cpan.org>
Wed, 2 Mar 2016 18:07:57 +0000 (11:07 -0700)
I added this assertion in cfbef7dc3.  It asserts that we have more to
parse.  The code in this function is quite complicated, and assumes in a
number of places that there is more to parse.  When we don't have more
to parse, 900 lines later, it throws an error.  It may be that you can't
get to the places where it assumes there is more to parse if this
assertion is false (I don't remember now from my tedious audit of this
code), but even if so, it is fragile to assume so, given the large
distance to where the error is thrown.  So throw the error right away
and avoid any existing or future breakage.

regcomp.c
t/re/reg_mesg.t

index 46b9f77..bbb998f 100644 (file)
--- a/regcomp.c
+++ b/regcomp.c
@@ -10313,7 +10313,9 @@ S_reg(pTHX_ RExC_state_t *pRExC_state, I32 paren, I32 *flagp,U32 depth)
          * indivisible */
         bool has_intervening_patws = paren == 2 && *(RExC_parse - 1) != '(';
 
          * indivisible */
         bool has_intervening_patws = paren == 2 && *(RExC_parse - 1) != '(';
 
-        assert(RExC_parse < RExC_end);
+        if (RExC_parse >= RExC_end) {
+           vFAIL("Unmatched (");
+        }
 
         if ( *RExC_parse == '*') { /* (*VERB:ARG) */
            char *start_verb = RExC_parse + 1;
 
         if ( *RExC_parse == '*') { /* (*VERB:ARG) */
            char *start_verb = RExC_parse + 1;
index 0763be0..7509f41 100644 (file)
@@ -146,6 +146,7 @@ my @death =
 '/(?i-l:foo)/' => 'Regexp modifier "l" may not appear after the "-" {#} m/(?i-l{#}:foo)/',
 
  '/((x)/' => 'Unmatched ( {#} m/({#}(x)/',
 '/(?i-l:foo)/' => 'Regexp modifier "l" may not appear after the "-" {#} m/(?i-l{#}:foo)/',
 
  '/((x)/' => 'Unmatched ( {#} m/({#}(x)/',
+ '/{(}/' => 'Unmatched ( {#} m/{({#}}/',    # [perl #127599]
 
  "/x{$inf_p1}/" => "Quantifier in {,} bigger than $inf_m1 {#} m/x{{#}$inf_p1}/",
 
 
  "/x{$inf_p1}/" => "Quantifier in {,} bigger than $inf_m1 {#} m/x{{#}$inf_p1}/",