This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Make sv_force_normal_flags cope with shared hash key scalars
authorNicholas Clark <nick@ccl4.org>
Sat, 6 Dec 2003 16:30:35 +0000 (16:30 +0000)
committerNicholas Clark <nick@ccl4.org>
Sat, 6 Dec 2003 16:30:35 +0000 (16:30 +0000)
(remember the pointer from SvPVX, reset the flags before SvGROW,
avoid crazy loops or read-from-free)

p4raw-id: //depot/perl@21854

sv.c

diff --git a/sv.c b/sv.c
index 5e61449..dc089b8 100644 (file)
--- a/sv.c
+++ b/sv.c
@@ -4497,14 +4497,17 @@ Perl_sv_force_normal_flags(pTHX_ register SV *sv, U32 flags)
     if (SvREADONLY(sv)) {
        if (SvFAKE(sv)) {
            char *pvx = SvPVX(sv);
+           int is_utf8 = SvUTF8(sv);
            STRLEN len = SvCUR(sv);
             U32 hash   = SvUVX(sv);
            SvFAKE_off(sv);
            SvREADONLY_off(sv);
+            SvPVX(sv) = 0;
+            SvLEN(sv) = 0;
            SvGROW(sv, len + 1);
            Move(pvx,SvPVX(sv),len,char);
            *SvEND(sv) = '\0';
-           unsharepvn(pvx, SvUTF8(sv) ? -(I32)len : len, hash);
+           unsharepvn(pvx, is_utf8 ? -(I32)len : len, hash);
        }
        else if (IN_PERL_RUNTIME)
            Perl_croak(aTHX_ PL_no_modify);