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

Re: [perl #21411] [slippery] Postponed RE with split()

Thread Previous | Thread Next
From:
Enache Adrian
Date:
March 4, 2003 04:28
Subject:
Re: [perl #21411] [slippery] Postponed RE with split()
Message ID:
20030304122015.GA810@ratsnest.hole
On Sun, Mar 02, 2003 at 05:41:38PM +0000, hv@crypt.org wrote:
> Enache Adrian <enache@rdslink.ro> wrote:
> :Simpler example:
> :$ perl -le 'print join "|", split /((??{$i++}))/,"-1-3-5-"'
> :
> :This should print '-|1|-|3|-|5|-' not '-|1|-|7|-|5|-'
> :
> :The expression inside (??{ ... }) corrupts the stack.
> 
> Thanks, patch applied as #18805.

$ perl -le 'split /(?{"FOO"})/,"abcde";print @_'
SEGV

That's split's stack swapping when the list it returns has to be
assigned to an array (@_ here) . See [perl #20912] too.

In an expression like:
  @a = split /(?{ .. CODE .. }) .. /, STRING;
the CODE will just use @a as its stack and may try to reallocate it
( this may happen with the regular Perl stack too, of course ).

A q-n-d fix is to put a SPAGAIN too there to keep PL_stack_base and
SP referring to the same array. ( see pp.c:4700 )
It will keep the coredump off, but certainly isn't a long term
solution.
-------------------------------------------------------------------
--- /arc/perl-current/pp.c	2003-03-03 08:45:50.000000000 +0200
+++ pp.c	2003-03-04 13:25:43.000000000 +0200
@@ -4647,6 +4647,7 @@ PP(pp_split)
     }
     else {
 	maxiters += slen * rx->nparens;
+	PUTBACK;
 	while (s < strend && --limit
 /*	       && (!rx->check_substr
 		   || ((s = CALLREG_INTUIT_START(aTHX_ rx, sv, s, strend,
@@ -4654,6 +4655,7 @@ PP(pp_split)
 */	       && CALLREGEXEC(aTHX_ rx, s, strend, orig,
 			      1 /* minend */, sv, NULL, 0))
 	{
+	    SPAGAIN;
 	    TAINT_IF(RX_MATCH_TAINTED(rx));
 	    if (RX_MATCH_COPIED(rx) && rx->subbeg != orig) {
 		m = s;
-------------------------------------------------------------------

Probably the right place to fix that is the EVAL case in S_regmatch.
What about a special stack for the '(?{ ... })' blocks to SWITCHSTACK
to it and then back there ?

Regards
Adi


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