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

Re: [perl #37102] Perl regexp state gets clobbered (includes a fix)

Thread Previous | Thread Next
From:
Rafael Garcia-Suarez
Date:
October 9, 2005 10:00
Subject:
Re: [perl #37102] Perl regexp state gets clobbered (includes a fix)
Message ID:
b77c1dce0510091000j72826367x65d91f9351431df8@mail.gmail.com
On 9/8/05, via RT Geoff Mottram <perlbug-followup@perl.org> wrote:
> The following regex was causing either an Out of Memory condition or a
> segmentation fault after two iterations:
>
>              if ($a =~ m/^([A-Za-z]+)(.*)/)
>
> It was caused by the PL_regeol variable of regexec.c getting overwritten
> when in the "av_store()" call on line 4370 of regexec.c (see gdb backtrace
> below):
>
>              if (a)
>                  sw = *a;
>              else if (si && doinit) {
>                  sw = swash_init("utf8", "", si, 1, 0);
>                  (void)av_store(av, 1, sw);
>              }
>
> When av_store is called, the previous positional parameter is
> de-referenced and its DESTROY method is called. I could not figure out
> what object was being destroyed but the gdb backtrace will probably ring a
> few bells for you. The script was working with UTF-8 content and wide
> characters, which I suspect was related to the problem. In any case, the
> DESTROY method that was called included a regular expression that would
> trash the state of the regular expression engine a few methods up the stack.

Given that your bug happens inside the debugger, I wonder whether the
following patch isn't more appropriate :


==== //depot/perl/pp_hot.c#415 - /opt/bleadperl/p4/perl/pp_hot.c ====
--- /home/rafael/tmp/tmp.14639.0        2005-10-09 18:59:52.901594208 +0200
+++ /opt/bleadperl/p4/perl/pp_hot.c     2005-10-09 18:57:32.849885304 +0200
@@ -2657,6 +2657,7 @@ PP(pp_entersub)
         if (CvASSERTION(cv) && PL_DBassertion)
            sv_setiv(PL_DBassertion, 1);

+       save_re_context();
        cv = get_db_sub(&sv, cv);
        if (!cv || (!CvXSUB(cv) && !CvSTART(cv)))
            DIE(aTHX_ "No DB::sub routine defined");
End of Patch.

However, I can't reproduce your problem, so I'm not sure if it fixes it.

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