This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
PATCH: [perl #101940]: BBC Tk
authorKarl Williamson <public@khwilliamson.com>
Sat, 29 Oct 2011 17:20:40 +0000 (11:20 -0600)
committerDavid Mitchell <davem@iabyn.com>
Wed, 13 Jun 2012 12:25:51 +0000 (13:25 +0100)
This commit that turned up this bug turns out merely exposes an
underlying problem that could be generated via other means.

regcomp.c was looking at the SvUTF8 flag on the input pattern before
doing an SvPV on it.  Generally the flag is considered not reliable
unless checked immediately after a SvPV.

I haven't been able to come up with a simple test case that reproduces
the bug.  I suspect that XS code is required to trigger it.

[ this is a re-application by davem of commit
  11951bcbfcaf4c260b0da0421e72fc80b4654f17 ]

regcomp.c

index 6e60737..8e9d335 100644 (file)
--- a/regcomp.c
+++ b/regcomp.c
@@ -5151,7 +5151,14 @@ Perl_re_op_compile(pTHX_ SV * const * const patternp, int pat_count,
        pat = *patternp;
     }
 
-    RExC_utf8 = RExC_orig_utf8 = SvUTF8(pat);
+    exp = SvPV(pat, plen);
+
+    if (plen == 0) { /* ignore the utf8ness if the pattern is 0 length */
+       RExC_utf8 = RExC_orig_utf8 = 0;
+    }
+    else {
+       RExC_utf8 = RExC_orig_utf8 = SvUTF8(pat);
+    }
     RExC_uni_semantics = 0;
     RExC_contains_locale = 0;
 
@@ -5163,12 +5170,7 @@ Perl_re_op_compile(pTHX_ SV * const * const patternp, int pat_count,
     }
 
     if (jump_ret == 0) {    /* First time through */
-       exp = SvPV(pat, plen);
        xend = exp + plen;
-       /* ignore the utf8ness if the pattern is 0 length */
-       if (plen == 0) {
-           RExC_utf8 = RExC_orig_utf8 = 0;
-       }
 
         DEBUG_COMPILE_r({
             SV *dsv= sv_newmortal();