In perl.git, the branch blead has been updated <http://perl5.git.perl.org/perl.git/commitdiff/a84e671a269f736a404a62f21caacc8a431c2aca?hp=77f118c279be3f2b4aaa364f584602f96d70b97c>
- Log ----------------------------------------------------------------- commit a84e671a269f736a404a62f21caacc8a431c2aca Author: Father Chrysostomos <[email protected]> Date: Thu Jun 6 08:47:31 2013 -0700 Stop (?[]) operators from leaking When a (?[]) extended charclass is compiled, the various operands are stored as inversion lists in separate SVs and then combined together into new inversion lists. The functions that take care of combining inversion lists only ever free one operand, and sometimes free none. Most of the operators in (?[]) were trusting the invlist functions to free everything that was no longer needed, causing (?[]) compilation to leak invlists. M regcomp.c M t/op/svleak.t commit 27350048d47bfa7c69df608e6b5bc6374052b46d Author: Father Chrysostomos <[email protected]> Date: Thu Jun 6 08:17:44 2013 -0700 perldiag: Document âExpecting '(?flags:(?[...'â M pod/perldiag.pod M t/porting/diag.t commit 3c6ca74ae1c7e83b535f999b51c2f19a9b583191 Author: Father Chrysostomos <[email protected]> Date: Thu Jun 6 06:22:45 2013 -0700 perldiag: Clarify why âFalse [] rangeâ can be F M pod/perldiag.pod ----------------------------------------------------------------------- Summary of changes: pod/perldiag.pod | 18 +++++++++++++++--- regcomp.c | 20 ++++++++++++++------ t/op/svleak.t | 8 +++++++- t/porting/diag.t | 1 - 4 files changed, 36 insertions(+), 11 deletions(-) diff --git a/pod/perldiag.pod b/pod/perldiag.pod index 6016648..21c0e91 100644 --- a/pod/perldiag.pod +++ b/pod/perldiag.pod @@ -1915,6 +1915,17 @@ to denote a capturing group of the form L<C<(?I<PARNO>)>|perlre/(?PARNO) (?-PARNO) (?+PARNO) (?R) (?0)>, but omitted the C<")">. +=item Expecting '(?flags:(?[...' in regex; marked by <-- HERE in m/%s/ + +(F) The C<(?[...])> extended character class regular expression +construct only allows character classes (including character class +escapes like C<\d>), operators, and parentheses. The one exception is +C<(?:...)> or C<(?flags:...)> containing exactly one C<(?[...])> construct. +This allows a regular expression containing just C<(?[...])> to be +interpolated. If you see this error message, then you probably +have some other C<(?...)> construct inside your character class. See +L<perlrecharclass/Extended Bracketed Character Classes>. + =item Experimental "%s" subs not enabled (F) To use lexical subs, you must first enable them: @@ -1945,9 +1956,10 @@ queue of such routines has been prematurely ended. (W regexp)(F) A character class range must start and end at a literal character, not another character class like C<\d> or C<[:alpha:]>. The "-" -in your false range is interpreted as a literal "-". Consider quoting the -"-", "\-". The <-- HERE shows whereabouts in the regular expression the -problem was discovered. See L<perlre>. +in your false range is interpreted as a literal "-". In a C<(?[...])> +construct, this is an error, rather than a warning. Consider quoting +the "-", "\-". The <-- HERE shows whereabouts in the regular expression +the problem was discovered. See L<perlre>. =item Fatal VMS error (status=%d) at %s, line %d diff --git a/regcomp.c b/regcomp.c index ca23653..1812028 100644 --- a/regcomp.c +++ b/regcomp.c @@ -11967,6 +11967,7 @@ S_handle_regex_sets(pTHX_ RExC_state_t *pRExC_state, SV** return_invlist, I32 *f } else { SV* top = av_pop(stack); + SV *prev = NULL; char current_operator; if (IS_OPERAND(top)) { @@ -11996,7 +11997,8 @@ S_handle_regex_sets(pTHX_ RExC_state_t *pRExC_state, SV** return_invlist, I32 *f goto handle_operand; case '&': - _invlist_intersection(av_pop(stack), + prev = av_pop(stack); + _invlist_intersection(prev, current, ¤t); av_push(stack, current); @@ -12004,12 +12006,14 @@ S_handle_regex_sets(pTHX_ RExC_state_t *pRExC_state, SV** return_invlist, I32 *f case '|': case '+': - _invlist_union(av_pop(stack), current, ¤t); + prev = av_pop(stack); + _invlist_union(prev, current, ¤t); av_push(stack, current); break; case '-': - _invlist_subtract(av_pop(stack), current, ¤t); + prev = av_pop(stack);; + _invlist_subtract(prev, current, ¤t); av_push(stack, current); break; @@ -12019,9 +12023,12 @@ S_handle_regex_sets(pTHX_ RExC_state_t *pRExC_state, SV** return_invlist, I32 *f SV* u = NULL; SV* element; - element = av_pop(stack); - _invlist_union(element, current, &u); - _invlist_intersection(element, current, &i); + prev = av_pop(stack); + _invlist_union(prev, current, &u); + _invlist_intersection(prev, current, &i); + /* _invlist_subtract will overwrite current + without freeing what it already contains */ + element = current; _invlist_subtract(u, i, ¤t); av_push(stack, current); SvREFCNT_dec_NN(i); @@ -12034,6 +12041,7 @@ S_handle_regex_sets(pTHX_ RExC_state_t *pRExC_state, SV** return_invlist, I32 *f Perl_croak(aTHX_ "panic: Unexpected item on '(?[ ])' stack"); } SvREFCNT_dec_NN(top); + SvREFCNT_dec(prev); } } diff --git a/t/op/svleak.t b/t/op/svleak.t index 8140ded..b97a5cb 100644 --- a/t/op/svleak.t +++ b/t/op/svleak.t @@ -15,7 +15,7 @@ BEGIN { use Config; -plan tests => 115; +plan tests => 121; # run some code N times. If the number of SVs at the end of loop N is # greater than (N-1)*delta at the end of loop 1, we've got a leak @@ -241,6 +241,12 @@ eleak(2,0,'/[[:ascii:]]/'); eleak(2,0,'/[[.zog.]]/'); eleak(2,0,'/[.zog.]/'); eleak(2,0,'no warnings; /(?[])/'); +eleak(2,0,'no warnings; /(?[[a]+[b]])/'); +eleak(2,0,'no warnings; /(?[[a]-[b]])/'); +eleak(2,0,'no warnings; /(?[[a]&[b]])/'); +eleak(2,0,'no warnings; /(?[[a]|[b]])/'); +eleak(2,0,'no warnings; /(?[[a]^[b]])/'); +eleak(2,0,'no warnings; /(?[![a]])/'); # These can generate one ref count, but just once. eleak(4,1,'chr(0x100) =~ /[[:punct:]]/'); diff --git a/t/porting/diag.t b/t/porting/diag.t index 25301a5..104c195 100644 --- a/t/porting/diag.t +++ b/t/porting/diag.t @@ -490,7 +490,6 @@ Don't know how to handle magic of type \%o -Dp not implemented on this platform Error reading "%s": %s execl not implemented! -Expecting '(?flags:(?[...' in regex; marked by <-- HERE in m/%s/ EVAL without pos change exceeded limit in regex Filehandle opened only for %sput Filehandle %s opened only for %sput -- Perl5 Master Repository
