Change 15275 by jhi@alpha on 2002/03/17 20:14:18

        Integrate perlio;
        
        Avoid overwrite of un-allocated memory when SvCUR > SvLEN
        
        Other :encoding oddities
         - we should really pop while we can still make method calls
           in case DESTROY does something.
         - Provide a no-op DESTROY
         - Use SvPV_only() rather than just SvPV_on()

Affected files ...

.... //depot/perl/ext/Encode/Encode.pm#71 integrate
.... //depot/perl/ext/Encode/Encode.xs#50 integrate
.... //depot/perl/ext/Encode/lib/Encode/Encoding.pm#3 integrate
.... //depot/perl/sv.c#528 integrate

Differences ...

==== //depot/perl/ext/Encode/Encode.pm#71 (text) ====
==== //depot/perl/ext/Encode/Encode.xs#50 (text) ====
Index: perl/ext/Encode/Encode.xs
--- perl/ext/Encode/Encode.xs.~1~       Sun Mar 17 13:30:05 2002
+++ perl/ext/Encode/Encode.xs   Sun Mar 17 13:30:05 2002
@@ -118,7 +118,7 @@
     }
     if (e->dataSV) {
        SvREFCNT_dec(e->dataSV);
-       e->bufsv = Nullsv;
+       e->dataSV = Nullsv;
     }
     return 0;
 }
@@ -227,7 +227,7 @@
            SvPVX(e->dataSV) = (char *) ptr;
            SvLEN(e->dataSV) = 0;  /* Hands off sv.c - it isn't yours */
            SvCUR_set(e->dataSV,use);
-           SvPOK_on(e->dataSV);
+           SvPOK_only(e->dataSV);
        }
        SvUTF8_off(e->dataSV);
        PUSHMARK(sp);
@@ -255,7 +255,7 @@
               (The copy is a pain - need a put-it-here option for decode.)
             */
            sv_setpvn(e->bufsv,s,len);
-           e->base.ptr = e->base.buf = (STDCHAR*)SvPVX(e->bufsv);
+           e->base.ptr = e->base.buf = (STDCHAR*)SvPVX(e->bufsv);
            e->base.end = e->base.ptr + SvCUR(e->bufsv);
            PerlIOBase(f)->flags |= PERLIO_F_RDBUF;
            SvUTF8_on(e->bufsv);
@@ -356,6 +356,7 @@
                SvPVX(str) = (char*)e->base.ptr;
                SvLEN(str) = 0;
                SvCUR_set(str, e->base.end - e->base.ptr);
+               SvPOK_only(str);
                SvUTF8_on(str);
                PUSHMARK(sp);
                XPUSHs(e->enc);
@@ -433,7 +434,7 @@
 PerlIO_funcs PerlIO_encode = {
     "encoding",
     sizeof(PerlIOEncode),
-    PERLIO_K_BUFFERED,
+    PERLIO_K_BUFFERED|PERLIO_K_DESTRUCT,
     PerlIOEncode_pushed,
     PerlIOEncode_popped,
     PerlIOBuf_open,
@@ -500,7 +501,7 @@
        int code;
        while ((code = do_encode(dir, s, &slen, d, dlen, &dlen, !check))) {
            SvCUR_set(dst, dlen+ddone);
-           SvPOK_on(dst);
+           SvPOK_only(dst);
 
 #if 0
            Perl_warn(aTHX_ "code=%d @ s=%d/%d/%d 
d=%d/%d/%d",code,slen,sdone,tlen,dlen,ddone,SvLEN(dst)-1);
@@ -569,7 +570,7 @@
            }
        }
        SvCUR_set(dst, dlen+ddone);
-       SvPOK_on(dst);
+       SvPOK_only(dst);
        if (check) {
            sdone = SvCUR(src) - (slen+sdone);
            if (sdone) {
@@ -580,7 +581,7 @@
     }
     else {
        SvCUR_set(dst, 0);
-       SvPOK_on(dst);
+       SvPOK_only(dst);
     }
     *SvEND(dst) = '\0';
     return dst;

==== //depot/perl/ext/Encode/lib/Encode/Encoding.pm#3 (text) ====
Index: perl/ext/Encode/lib/Encode/Encoding.pm
--- perl/ext/Encode/lib/Encode/Encoding.pm.~1~  Sun Mar 17 13:30:05 2002
+++ perl/ext/Encode/lib/Encode/Encoding.pm      Sun Mar 17 13:30:05 2002
@@ -20,5 +20,7 @@
 
 sub new_sequence { return $_[0] }
 
+sub DESTROY {}
+
 1;
 __END__

==== //depot/perl/sv.c#528 (text) ====
Index: perl/sv.c
--- perl/sv.c.~1~       Sun Mar 17 13:30:05 2002
+++ perl/sv.c   Sun Mar 17 13:30:05 2002
@@ -1540,6 +1540,8 @@
 {
     register char *s;
 
+
+
 #ifdef HAS_64K_LIMIT
     if (newlen >= 0x10000) {
        PerlIO_printf(Perl_debug_log,
@@ -1565,6 +1567,7 @@
     }
     else
        s = SvPVX(sv);
+
     if (newlen > SvLEN(sv)) {          /* need more room? */
        if (SvLEN(sv) && s) {
 #if defined(MYMALLOC) && !defined(LEAKTEST)
@@ -1585,7 +1588,7 @@
            }
            New(703, s, newlen, char);
            if (SvPVX(sv) && SvCUR(sv)) {
-               Move(SvPVX(sv), s, SvCUR(sv), char);
+               Move(SvPVX(sv), s, (newlen < SvCUR(sv)) ? newlen : SvCUR(sv), char);
            }
        }
        SvPV_set(sv, s);
@@ -3152,10 +3155,10 @@
 
 Copies a stringified representation of the source SV into the
 destination SV.  Automatically performs any necessary mg_get and
-coercion of numeric values into strings.  Guaranteed to preserve 
+coercion of numeric values into strings.  Guaranteed to preserve
 UTF-8 flag even from overloaded objects.  Similar in nature to
-sv_2pv[_flags] but operates directly on an SV instead of just the 
-string.  Mostly uses sv_2pv_flags to do its work, except when that 
+sv_2pv[_flags] but operates directly on an SV instead of just the
+string.  Mostly uses sv_2pv_flags to do its work, except when that
 would lose the UTF-8'ness of the PV.
 
 =cut
@@ -3917,7 +3920,6 @@
        }
        else {                          /* have to copy actual string */
            STRLEN len = SvCUR(sstr);
-
            SvGROW(dstr, len + 1);      /* inlined from sv_setpvn */
            Move(SvPVX(sstr),SvPVX(dstr),len,char);
            SvCUR_set(dstr, len);
End of Patch.

Reply via email to