develooper Front page | perl.perl5.porters | Postings from December 2004

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

Thread Previous
From:
Nicholas Clark
Date:
December 31, 2004 07:37
Subject:
Re: [perl #33185] UTF-8 string substitution corrupts memory
Message ID:
20041231153749.GN77507@plum.flirble.org
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.

Aha. I was rather hoping that someone would be able to tell me if the changes
were going to be relevant. The "simplest" fix appears to be add
save_re_context(); after the ENTER in

    if (!gv_fetchmeth(stash, "SWASHNEW", 8, -1)) {	/* demand load utf8 */
	ENTER;
	errsv_save = newSVsv(ERRSV);
	Perl_load_module(aTHX_ PERL_LOADMOD_NOIMPORT, newSVpvn(pkg,pkg_len),
			 Nullsv);
	if (!SvTRUE(ERRSV))
	    sv_setsv(ERRSV, errsv_save);
	SvREFCNT_dec(errsv_save);
	LEAVE;
    }


except that seems to be wasteful, as it would mean doing all the save work
twice, because of the existing save_re_context() later in Perl_swatch_init.
I was hoping that there was a good way to save the regexp engine's context
just once for the entire function.

Nicholas Clark

Thread Previous


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