In perl.git, the branch blead has been updated

<http://perl5.git.perl.org/perl.git/commitdiff/9f28c6384ccf40ab7e158f98d343a59c296c6074?hp=8c9e24c7f6088cb5fe0779c2c11c1fb4ca8ae693>

- Log -----------------------------------------------------------------
commit 9f28c6384ccf40ab7e158f98d343a59c296c6074
Author: Joel Berger <[email protected]>
Date:   Sat Dec 1 10:15:36 2012 -0600

    Cwd::fast_abs_path's untaint should allow for multiline directories
    
    This bug was noticed via https://github.com/dagolden/file-chdir/issues/3 
and testing has led to this being the cause.
    The problem is worse on some platforms (notably cygwin in this case) when 
abs_path is implemented by fast_abs_path.
    Since File::chdir tests for proper behavior when a directory contains a 
newline, this bug then breaks File::chdir (one of my favorites and very useful 
xplatform tool).
    
    Yes this should have tests, but since it will involve creating a directory 
with a newline, I thought I would do better to leave that to someone with 
better knowledge than I.

M       dist/Cwd/Cwd.pm

commit 52ee8d0ab0016f47e2280ef34ee0f8e2d7ee2590
Author: Father Chrysostomos <[email protected]>
Date:   Sun Dec 2 18:53:23 2012 -0800

    [perl #115962] cwd.t: Add test for fast_abs_path in LF dir

M       dist/Cwd/t/cwd.t

commit ea5a229a68de4c28f958df96cd57ae768501de7a
Author: Father Chrysostomos <[email protected]>
Date:   Sun Dec 2 17:46:24 2012 -0800

    Stop /[\i]/ from leaking under fatal warnings
    
    This commit arranges for the regexp and one temporary sv in S_regclass
    to be freed in case the ‘Unrecognized escape \x in character class’
    warning proves fatal.

M       regcomp.c
M       t/op/svleak.t

commit 7d12ff0f842717c6be578ba6e7e2463a8d27673e
Author: Father Chrysostomos <[email protected]>
Date:   Sun Dec 2 17:40:36 2012 -0800

    Stop /(?{})+/ from leaking under fatal warnings
    
    This commit arranges for the regexp to be freed in case the ‘blah blah
    blah matches null string many times in regex’ warning proves fatal.

M       regcomp.c
M       t/op/svleak.t

commit 6e240d0bbb2875825a18bd4f02983684ddfefa5f
Author: Father Chrysostomos <[email protected]>
Date:   Sun Dec 2 17:34:44 2012 -0800

    Make PL_sawampersand checks conditional on PERL_SAWAMPERSAND
    
    This does not actually make any difference, since PL_sawampersand is
    a constant when PERL_SAWAMPERSAND is undefined.  It just makes the
    code clearer.

M       pp_hot.c

commit 77381e15105d6b7991dbe57c5ee42bb4b06dba0f
Author: Father Chrysostomos <[email protected]>
Date:   Sun Dec 2 17:27:41 2012 -0800

    Stop /(?{})?/ from leaking under fatal warnings
    
    Fatal errors in regexp compilation do SAVEFREESV before croaking, to
    make sure the regexp is freed.
    
    Warnings that happen after the sizing pass need to be protected the
    same way, in case they are fatal.
    
    This commit arranges for the regexp to be freed in case the ‘Quanti-
    fier unexpected on zero-length expression’ warning proves fatal.
    
    /(?{})?/ also triggers some others leaks.  Before re_op_compile calls
    S_study_chunk, it allocates three scalars for study_chunk’s use.  Some
    of those are freed after the call to study_chunk, while others become
    part of the regexp.
    
    I surrounded the allocation and freeing with an ENTER/LEAVE pair,
    using SAVEFREESV to free them when there is a croak.  So those cases
    SvREFCNT_dec was used, it is simply omitted.  Those cases where it was
    omitted now have SvREFCNT_inc.
    
    One more complication was that sometimes there is a goto between the
    ENTER and the LEAVE which restarts the surrounding code.  It already=
    took those scalars into account, freeing them.  But to balance ENTER/
    LEAVE pairs properly I had to do a LEAVE just before the goto, and
    remove the freeing of the SVs after the goto.
    
    The new name of the macro that uses goto was inspired by
    Acme::ButFirst.

M       regcomp.c
M       t/op/svleak.t

commit a5e7bc5140f5e3ea032317511826fa1cc38ec7fc
Author: Father Chrysostomos <[email protected]>
Date:   Fri Nov 30 20:20:19 2012 -0800

    Remove use of SAVEDESTRUCTOR_X(clear_re...) from regcomp.c
    
    The purpose of this is to free the regexp when croaking.
    SAVEDESTRUCTOR_X calls clear_re on scope exit.  clear_re does
    ReREFCNT_dec.
    
    It used to be necessary to do it this way before regular expres-
    sions were SVs.
    
    Since v5.10.0-145-g84679df, regexps have been SVs, and ReREFCNT_dec is
    effectively an alias for SvREFCNT_dec.
    
    There will be one less function call on scope exit when regexp compi-
    lation croaks if we use SAVEFREESV instead of SAVEDESTRUCTOR_X.

M       regcomp.c
-----------------------------------------------------------------------

Summary of changes:
 dist/Cwd/Cwd.pm  |    4 +-
 dist/Cwd/t/cwd.t |   12 ++++++++++-
 pp_hot.c         |   20 +++++++++++++++++-
 regcomp.c        |   56 ++++++++++++++++++++++++++++-------------------------
 t/op/svleak.t    |    2 +-
 5 files changed, 62 insertions(+), 32 deletions(-)

diff --git a/dist/Cwd/Cwd.pm b/dist/Cwd/Cwd.pm
index f772bf4..888c505 100644
--- a/dist/Cwd/Cwd.pm
+++ b/dist/Cwd/Cwd.pm
@@ -624,8 +624,8 @@ sub fast_abs_path {
 
     # Detaint else we'll explode in taint mode.  This is safe because
     # we're not doing anything dangerous with it.
-    ($path) = $path =~ /(.*)/;
-    ($cwd)  = $cwd  =~ /(.*)/;
+    ($path) = $path =~ /(.*)/s;
+    ($cwd)  = $cwd  =~ /(.*)/s;
 
     unless (-e $path) {
        _croak("$path: No such file or directory");
diff --git a/dist/Cwd/t/cwd.t b/dist/Cwd/t/cwd.t
index c9a2187..f7b03ed 100644
--- a/dist/Cwd/t/cwd.t
+++ b/dist/Cwd/t/cwd.t
@@ -36,7 +36,7 @@ if ($IsVMS) {
     $vms_mode = 0 if ($vms_unix_rpt);
 }
 
-my $tests = 30;
+my $tests = 31;
 # _perl_abs_path() currently only works when the directory separator
 # is '/', so don't test it when it won't work.
 my $EXTRA_ABSPATH_TESTS = ($Config{prefix} =~ m/\//) && $^O ne 'cygwin';
@@ -245,6 +245,16 @@ SKIP: {
     if $EXTRA_ABSPATH_TESTS;
 }
 
+SKIP: {
+  my $dir = "${$}a\nx";
+  mkdir $dir or skip "OS does not support dir names containing LF";
+  chdir $dir or skip "OS cannot chdir into LF";
+  eval { Cwd::fast_abs_path() };
+  is $@, "", 'fast_abs_path does not die in dir whose name contains LF';
+  chdir File::Spec->updir;
+  rmdir $dir;
+}
+
 
 #############################################
 # These routines give us sort of a poor-man's cross-platform
diff --git a/pp_hot.c b/pp_hot.c
index e991567..333c593 100644
--- a/pp_hot.c
+++ b/pp_hot.c
@@ -1400,10 +1400,13 @@ PP(pp_match)
            }
        }
     }
+#ifdef PERL_SAWAMPERSAND
     if (       RX_NPARENS(rx)
             || PL_sawampersand
             || (RX_EXTFLAGS(rx) & (RXf_EVAL_SEEN|RXf_PMf_KEEPCOPY))
-    ) {
+    )
+#endif
+    {
        r_flags |= (REXEC_COPY_STR|REXEC_COPY_SKIP_PRE);
         /* in @a =~ /(.)/g, we iterate multiple times, but copy the buffer
          * only on the first iteration. Therefore we need to copy $' as well
@@ -1431,11 +1434,13 @@ PP(pp_match)
 
        if (!s)
            goto nope;
+#ifdef PERL_SAWAMPERSAND
        if ( (RX_EXTFLAGS(rx) & RXf_CHECK_ALL)
             && !PL_sawampersand
             && !(RX_EXTFLAGS(rx) & RXf_PMf_KEEPCOPY)
             && !SvROK(TARG))   /* Cannot trust since INTUIT cannot guess ^ */
            goto yup;
+#endif
     }
     if (!CALLREGEXEC(rx, (char*)s, (char *)strend, (char*)truebase,
                     minmatch, TARG, NUM2PTR(void*, gpos), r_flags))
@@ -1537,7 +1542,9 @@ PP(pp_match)
        RETPUSHYES;
     }
 
+#ifdef PERL_SAWAMPERSAND
 yup:                                   /* Confirmed by INTUIT */
+#endif
     if (rxtainted)
        RX_MATCH_TAINTED_on(rx);
     TAINT_IF(RX_MATCH_TAINTED(rx));
@@ -1569,7 +1576,10 @@ yup:                                     /* Confirmed by 
INTUIT */
        RX_SUBLEN(rx) = strend - truebase;
        goto gotcha;
     }
-    if (PL_sawampersand || RX_EXTFLAGS(rx) & RXf_PMf_KEEPCOPY) {
+#ifdef PERL_SAWAMPERSAND
+    if (PL_sawampersand || RX_EXTFLAGS(rx) & RXf_PMf_KEEPCOPY)
+#endif
+    {
        I32 off;
 #ifdef PERL_ANY_COW
        if (SvCANCOW(TARG)) {
@@ -1599,10 +1609,12 @@ yup:                                    /* Confirmed by 
INTUIT */
        off = RX_OFFS(rx)[0].start = s - t;
        RX_OFFS(rx)[0].end = off + RX_MINLENRET(rx);
     }
+#ifdef PERL_SAWAMPERSAND
     else {                     /* startp/endp are used by @- @+. */
        RX_OFFS(rx)[0].start = s - truebase;
        RX_OFFS(rx)[0].end = s - truebase + RX_MINLENRET(rx);
     }
+#endif
     /* match via INTUIT shouldn't have any captures. Let @-, @+, $^N know */
     assert(!RX_NPARENS(rx));
     RX_LASTPAREN(rx) = RX_LASTCLOSEPAREN(rx) = 0;
@@ -2222,12 +2234,16 @@ PP(pp_subst)
        rx = PM_GETRE(pm);
     }
 
+#ifdef PERL_SAWAMPERSAND
     r_flags = (    RX_NPARENS(rx)
                 || PL_sawampersand
                 || (RX_EXTFLAGS(rx) & (RXf_EVAL_SEEN|RXf_PMf_KEEPCOPY))
               )
           ? REXEC_COPY_STR
           : 0;
+#else
+    r_flags = REXEC_COPY_STR;
+#endif
 
     orig = m = s;
     if (RX_EXTFLAGS(rx) & RXf_USE_INTUIT) {
diff --git a/regcomp.c b/regcomp.c
index 9903510..a595a8c 100644
--- a/regcomp.c
+++ b/regcomp.c
@@ -449,7 +449,7 @@ static const scan_data_t zero_scan_data =
     IV len = RExC_end - RExC_precomp;                                  \
                                                                        \
     if (!SIZE_ONLY)                                                    \
-       SAVEDESTRUCTOR_X(clear_re,(void*)RExC_rx_sv);                   \
+       SAVEFREESV(RExC_rx_sv);                                         \
     if (len > RegexLengthToShowInErrorMessages) {                      \
        /* chop 10 shorter than the max, to ensure meaning of "..." */  \
        len = RegexLengthToShowInErrorMessages - 10;                    \
@@ -480,7 +480,7 @@ static const scan_data_t zero_scan_data =
  */
 #define        vFAIL(m) STMT_START {                           \
     if (!SIZE_ONLY)                                    \
-       SAVEDESTRUCTOR_X(clear_re,(void*)RExC_rx_sv);   \
+       SAVEFREESV(RExC_rx_sv);                         \
     Simple_vFAIL(m);                                   \
 } STMT_END
 
@@ -498,7 +498,7 @@ static const scan_data_t zero_scan_data =
  */
 #define        vFAIL2(m,a1) STMT_START {                       \
     if (!SIZE_ONLY)                                    \
-       SAVEDESTRUCTOR_X(clear_re,(void*)RExC_rx_sv);   \
+       SAVEFREESV(RExC_rx_sv);                         \
     Simple_vFAIL2(m, a1);                              \
 } STMT_END
 
@@ -517,7 +517,7 @@ static const scan_data_t zero_scan_data =
  */
 #define        vFAIL3(m,a1,a2) STMT_START {                    \
     if (!SIZE_ONLY)                                    \
-       SAVEDESTRUCTOR_X(clear_re,(void*)RExC_rx_sv);   \
+       SAVEFREESV(RExC_rx_sv);                         \
     Simple_vFAIL3(m, a1, a2);                          \
 } STMT_END
 
@@ -695,8 +695,6 @@ DEBUG_OPTIMISE_MORE_r(if(data){                             
         \
     PerlIO_printf(Perl_debug_log,"\n");                              \
 });
 
-static void clear_re(pTHX_ void *r);
-
 /* Mark that we cannot extend a found fixed substring at this point.
    Update the longest found anchored substring and the longest found
    floating substrings if needed. */
@@ -3873,8 +3871,11 @@ S_study_chunk(pTHX_ RExC_state_t *pRExC_state, regnode 
**scanp,
                    && data && !(data->flags & (SF_HAS_PAR|SF_IN_PAR))
                    && maxcount <= REG_INFTY/3) /* Complement check for big 
count */
                {
+                   /* Fatal warnings may leak the regexp without this: */
+                   SAVEFREESV(RExC_rx_sv);
                    ckWARNreg(RExC_parse,
                              "Quantifier unexpected on zero-length 
expression");
+                   ReREFCNT_inc(RExC_rx_sv);
                }
 
                min += minnext * mincount;
@@ -4872,13 +4873,18 @@ Perl_reginitcolors(pTHX)
 
 
 #ifdef TRIE_STUDY_OPT
-#define CHECK_RESTUDY_GOTO                                  \
+#define CHECK_RESTUDY_GOTO_butfirst(dOsomething)            \
+    STMT_START {                                            \
         if (                                                \
               (data.flags & SCF_TRIE_RESTUDY)               \
               && ! restudied++                              \
-        )     goto reStudy
+        ) {                                                 \
+            dOsomething;                                    \
+            goto reStudy;                                   \
+        }                                                   \
+    } STMT_END
 #else
-#define CHECK_RESTUDY_GOTO
+#define CHECK_RESTUDY_GOTO_butfirst
 #endif        
 
 /*
@@ -6044,11 +6050,6 @@ reStudy:
             RExC_seen |= REG_TOP_LEVEL_BRANCHES;
         else
             RExC_seen &= ~REG_TOP_LEVEL_BRANCHES;
-        if (data.last_found) {
-            SvREFCNT_dec(data.longest_fixed);
-           SvREFCNT_dec(data.longest_float);
-           SvREFCNT_dec(data.last_found);
-       }
        StructCopy(&zero_scan_data, &data, scan_data_t);
     }
 #else
@@ -6214,6 +6215,10 @@ reStudy:
        data.longest_float = newSVpvs("");
        data.last_found = newSVpvs("");
        data.longest = &(data.longest_fixed);
+       ENTER_with_name("study_chunk");
+       SAVEFREESV(data.longest_fixed);
+       SAVEFREESV(data.longest_float);
+       SAVEFREESV(data.last_found);
        first = scan;
        if (!ri->regstclass) {
            cl_init(pRExC_state, &ch_class);
@@ -6228,7 +6233,7 @@ reStudy:
             SCF_DO_SUBSTR | SCF_WHILEM_VISITED_POS | stclass_flag,0);
 
 
-        CHECK_RESTUDY_GOTO;
+        CHECK_RESTUDY_GOTO_butfirst(LEAVE_with_name("study_chunk"));
 
 
        if ( RExC_npar == 1 && data.longest == &(data.longest_fixed)
@@ -6238,7 +6243,6 @@ reStudy:
             && (!(RExC_seen & REG_SEEN_GPOS) || (r->extflags & RXf_ANCH_GPOS)))
            r->extflags |= RXf_CHECK_ALL;
        scan_commit(pRExC_state, &data,&minlen,0);
-       SvREFCNT_dec(data.last_found);
 
        longest_float_length = CHR_SVLEN(data.longest_float);
 
@@ -6261,10 +6265,10 @@ reStudy:
            r->float_max_offset = data.offset_float_max;
            if (data.offset_float_max < I32_MAX) /* Don't offset infinity */
                r->float_max_offset -= data.lookbehind_float;
+           SvREFCNT_inc_simple_void_NN(data.longest_float);
        }
        else {
            r->float_substr = r->float_utf8 = NULL;
-           SvREFCNT_dec(data.longest_float);
            longest_float_length = 0;
        }
 
@@ -6283,12 +6287,13 @@ reStudy:
                                 data.flags & SF_FIX_BEFORE_MEOL))
         {
            r->anchored_offset = data.offset_fixed - data.lookbehind_fixed;
+           SvREFCNT_inc_simple_void_NN(data.longest_fixed);
        }
        else {
            r->anchored_substr = r->anchored_utf8 = NULL;
-           SvREFCNT_dec(data.longest_fixed);
            longest_fixed_length = 0;
        }
+       LEAVE_with_name("study_chunk");
 
        if (ri->regstclass
            && (OP(ri->regstclass) == REG_ANY || OP(ri->regstclass) == SANY))
@@ -6363,7 +6368,7 @@ reStudy:
        minlen = study_chunk(pRExC_state, &scan, &minlen, &fake, scan + 
RExC_size,
            &data, -1, NULL, NULL, SCF_DO_STCLASS_AND|SCF_WHILEM_VISITED_POS,0);
         
-        CHECK_RESTUDY_GOTO;
+        CHECK_RESTUDY_GOTO_butfirst(NOOP);
 
        r->check_substr = r->check_utf8 = r->anchored_substr = r->anchored_utf8
                = r->float_substr = r->float_utf8 = NULL;
@@ -9648,10 +9653,12 @@ S_regpiece(pTHX_ RExC_state_t *pRExC_state, I32 *flagp, 
U32 depth)
     }
   nest_check:
     if (!SIZE_ONLY && !(flags&(HASWIDTH|POSTPONED)) && max > REG_INFTY/3) {
+       SAVEFREESV(RExC_rx_sv); /* in case of fatal warnings */
        ckWARN3reg(RExC_parse,
                   "%.*s matches null string many times",
                   (int)(RExC_parse >= origparse ? RExC_parse - origparse : 0),
                   origparse);
+       ReREFCNT_inc(RExC_rx_sv);
     }
 
     if (RExC_parse < RExC_end && *RExC_parse == '?') {
@@ -11841,9 +11848,13 @@ parseit:
            default:
                /* Allow \_ to not give an error */
                if (!SIZE_ONLY && isALNUM(value) && value != '_') {
+                   SAVEFREESV(RExC_rx_sv);
+                   SAVEFREESV(listsv);
                    ckWARN2reg(RExC_parse,
                               "Unrecognized escape \\%c in character class 
passed through",
                               (int)value);
+                   ReREFCNT_inc(RExC_rx_sv);
+                   SvREFCNT_inc_simple_void_NN(listsv);
                }
                break;
            }
@@ -14730,13 +14741,6 @@ Perl_save_re_context(pTHX)
 }
 #endif
 
-static void
-clear_re(pTHX_ void *r)
-{
-    dVAR;
-    ReREFCNT_dec((REGEXP *)r);
-}
-
 #ifdef DEBUGGING
 
 STATIC void
diff --git a/t/op/svleak.t b/t/op/svleak.t
index 59ff7f8..ad67259 100644
--- a/t/op/svleak.t
+++ b/t/op/svleak.t
@@ -98,10 +98,10 @@ eleak(2, 0, "$f 'misc'; our\$a,our\$a", 'double our with 
fatal warnings');
 eleak(2, 0, "$f 'closure';
              sub foo { my \$x; format=\n\@\n\$x\n.\n} write; ",
      'format closing over unavailable var with fatal warnings');
-$::TODO = 'still leaks';
 eleak(2, 0, "$all /(?{})?/ ", '(?{})? with fatal warnings');
 eleak(2, 0, "$all /(?{})+/ ", '(?{})+ with fatal warnings');
 eleak(2, 0, "$all /[\\i]/ ", 'invalid charclass escape with fatal warns');
+$::TODO = 'still leaks';
 eleak(2, 0, "$all /[:foo:]/ ", '/[:foo:]/ with fatal warnings');
 eleak(2, 0, "$all /[a-\\d]/ ", '[a-\d] char class with fatal warnings');
 eleak(2, 0, "$all v111111111111111111111111111111111111111111111111",

--
Perl5 Master Repository

Reply via email to