develooper Front page | perl.perl5.porters | Postings from September 2012

Re: Postponed regex eval produces SIGSEGV

Thread Previous | Thread Next
From:
=?utf-8?B?SmnFmcOtIFbDoWNsYXbDrWs=?=
Date:
September 5, 2012 10:36
Subject:
Re: Postponed regex eval produces SIGSEGV
Message ID:
20120905173405.GA10170@petamem.com
On August 27, 2012 03:09, Dave Mitchell wrote:
> > The problem here is infinite recursion. Within (??{}), $_ is set to the
> > string currently being matched (i.e. "a"), while an empty regex m{},
> > means 'use the last regex', i.e. the .(??{...})/. So it will infinitely
> > recurse executing the same regex, until the C stack blows and a SEGV
> > occurs.

Hi Dave,

I'd been attempting to give a minimal piece of code and finally picked a very
specific case ;-)

Please, check also this one. There is no empty regex and it produces
SIGSEGV instead of returning false.

Let's compare these calls:

> perl -e 'print 1 if "3" =~  m{(??{$_ =~ m{(??{$_ =~ m{(?=[3-5])(?=[1-4])} ? qr{a\A} : qr{.*}})} ? qr{a\A} : qr{.*}})}'
1
> perl -e 'print 1 if "4" =~  m{(??{$_ =~ m{(??{$_ =~ m{(?=[3-5])(?=[1-4])} ? qr{a\A} : qr{.*}})} ? qr{a\A} : qr{.*}})}'
1
> perl -e 'print 1 if "5" =~  m{(??{$_ =~ m{(??{$_ =~ m{(?=[3-5])(?=[1-4])} ? qr{a\A} : qr{.*}})} ? qr{a\A} : qr{.*}})}'
Segmentation fault

Regexes are totaly same. Calls differs in tested string only. The first
two works and the last one ends with SIGSEGV.

In fact, regular expression used above is NOT NOT (?=[3-5])(?=[1-4]),
hence it should simply be equivalent to (?=[3-5])(?=[1-4]). In other
words - strings containing "3" or "4" should match.

Why it crashes after not match?

BTW: I've used perl5.14.2. I've also tried to run it in perlbrew and it
works there even in perl5.14.2 (= no SEGV). I wonder why... It also crash
on another computer with v5.16.1.

-- 
best regards,

     Jiří Václavík - PetaMem R&D

     - The PetaMem Group - Prague/Nuremberg - www.petamem.com -

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