develooper Front page | perl.perl5.porters | Postings from March 2005

Re: [perl #33185] UTF-8 string substitution corrupts memory

Thread Previous | Thread Next
From:
Dave Mitchell
Date:
March 26, 2005 13:56
Subject:
Re: [perl #33185] UTF-8 string substitution corrupts memory
Message ID:
20050326215739.GP2793@iabyn.com
On Fri, Dec 31, 2004 at 04:11:16PM +0000, Dave Mitchell wrote:
> On Fri, Dec 31, 2004 at 03:04:49PM +0000, hv@crypt.org wrote:
> > Nicholas Clark <nick@ccl4.org> wrote:
> > :The appended patch seems to cure the problem for me, but I'm not confident
> > :that it's the correct way.
> > 
> > I notice that this changes the order things are stacked; I'm not sure if
> > that's ever going to be relevant. In particularly this swaps the first
> > two of the sequence:
> >   PUSHSTACKi; ENTER; LEAVE; POPSTACK
> > .. but I'm not sure what they all do without expanding a lot of macros.
> 
> I'd have thought that the better approach would be to move the
> 
>     if (!gv_fetchmeth(stash, "SWASHNEW", 8, -1)) {	/* demand load utf8 */
> 
> block further down to just above the line
> 
>     if (call_method("SWASHNEW", G_SCALAR))
> 
> then the call to Perl_load_module is protected by the PUSHSTACKi. Note
> that PUSHSTACKi is needed any place where the caller isn't prepared for
> the stack to get extended and thus possibly reallocated (thus invalidating
> SP etc). It gives you a brand new stack to play with.

Nicolas just reminded of this outstanding issue from December, so I've
committed the following change. It (hopefully) does all the state saving
needed *before* doing the require.

Dave.

-- 
Spock (or Data) is fired from his high-ranking position for not being able
to understand the most basic nuances of about one in three sentences that
anyone says to him.
    -- Things That Never Happen in "Star Trek" #19

Change 24084 by davem@davem-splatty on 2005/03/26 21:25:47

	[perl #33185] UTF-8 string substitution corrupts memory
	The implicit call of 'require utf8' triggered by code like
	    "\x{100}" =~ /[[:print:]]/
	wasn't saving state correctly first.

Affected files ...

... //depot/perl/utf8.c#223 edit

Differences ...

==== //depot/perl/utf8.c#223 (text) ====

@@ -1578,6 +1578,11 @@
     HV *stash = gv_stashpvn(pkg, pkg_len, FALSE);
     SV* errsv_save;
 
+    PUSHSTACKi(PERLSI_MAGIC);
+    ENTER;
+    SAVEI32(PL_hints);
+    PL_hints = 0;
+    save_re_context();
     if (!gv_fetchmeth(stash, "SWASHNEW", 8, -1)) {	/* demand load utf8 */
 	ENTER;
 	errsv_save = newSVsv(ERRSV);
@@ -1589,7 +1594,6 @@
 	LEAVE;
     }
     SPAGAIN;
-    PUSHSTACKi(PERLSI_MAGIC);
     PUSHMARK(SP);
     EXTEND(SP,5);
     PUSHs(sv_2mortal(newSVpvn(pkg, pkg_len)));
@@ -1598,10 +1602,6 @@
     PUSHs(sv_2mortal(newSViv(minbits)));
     PUSHs(sv_2mortal(newSViv(none)));
     PUTBACK;
-    ENTER;
-    SAVEI32(PL_hints);
-    PL_hints = 0;
-    save_re_context();
     if (IN_PERL_COMPILETIME) {
 	/* XXX ought to be handled by lex_start */
 	SAVEI32(PL_in_my);

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About