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

trying to fix #20154, #20357

Thread Next
From:
Enache Adrian
Date:
February 6, 2003 12:26
Subject:
trying to fix #20154, #20357
Message ID:
20030206203359.GA18190@ratsnest.hole
#20154, #20357 are bug reports about Perl (5.8.0, 5.9.0) getting SEGV
when exiting a continued loop which contains goto's:

for(;$a<1; $a++) { goto A; A: }
{ goto A; A: } continue { }
until ($a) { goto A } continue { A: $a++ }
...
all these dump core.

foreach (1) { goto A; A: } continue {}

this panics.

The segfault happens because Perl tries to pop a bogus context frame
which was erroneously pushed by pp_goto(), fooled by the scope built
by newWHILEOP() around the {} block into thinking it has to do with
something like:
	goto A; ... { A: } ...
(see pp_ctl.c Perl_pp_goto():2357, S_dofindlabel():2015)

This bug looks like a regression from 5.6.1 but isn't quite so: it
was there, but Perl didn't dump core because the free memory was
then zeroed. Now it's filled with 0xabababab...

Adding a new 'COP' at the beginning of that block makes all work OK.
(S_dofindlabel start searching from there instead of the control op
before 'for', 'while', etc.)

Unfortunately, it breaks Deparse:
# perl -MO=Deparse -e 'for(;$a<1;$a++) { goto A; A: }'
for (; $a < 1; ++$a) {
    do {
        goto A;
        A:
    };
}

I tried changing pp_goto() or S_dofindlabel() instead, but I didn't
find any way to do it reliably.

Anyone who knows better ?

Anyway, here's the patch:
------------------------------------------------------------------------
--- /arc/perl-current/op.c	2003-02-04 23:12:19.000000000 +0200
+++ perl-current/op.c	2003-02-06 20:49:44.000000000 +0200
@@ -3579,7 +3579,8 @@ Perl_newWHILEOP(pTHX_ I32 flags, I32 deb
     if (!block)
 	block = newOP(OP_NULL, 0);
     else if (cont) {
-	block = scope(block);
+	block = scope(prepend_elem(OP_LINESEQ,
+			newSTATEOP(0, Nullch, Nullop), block));
     }
 
     if (cont) {
------------------------------------------------------------------------

Regards
Adi

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