develooper Front page | perl.perl5.porters | Postings from July 2009

[perl #68020] Evil combination of regexes, lexicals, and autovivication

Thread Next
From:
John Peacock
Date:
July 30, 2009 03:02
Subject:
[perl #68020] Evil combination of regexes, lexicals, and autovivication
Message ID:
rt-3.6.HEAD-2466-1248893199-1087.68020-75-0@perl.org
# New Ticket Created by  John Peacock 
# Please include the string:  [perl #68020]
# in the subject line of all future correspondence about this issue. 
# <URL: http://rt.perl.org/rt3/Ticket/Display.html?id=68020 >



This is a bug report for perl from jpeacock@cpan.org,
generated with the help of perlbug 1.36 running under perl 5.10.0.


-----------------------------------------------------------------
[Please enter your report here]

Schwern and I simultaneously discovered that some hash tests were 
failing in Damian's Regex::Grammars.  But it turns out to be some 
insideous combination of regexes, lexicals, and autovivication and not 
depend on R::G at all.  Damian came up with the following script:

   use 5.010;

   my $rx = qr{ (?{ @arr = [1]; $arr[-1][0] = 0; my $var; }) }x;

   #my $dummy1 = '';
   #my $dummy2 = '';

   my $line = "";
   $line =~ $rx;

   say 'fail' if !defined $line;

If I run it as is, I get a segfault.  If I uncomment one of the
$dummy assignments, it passes.  If I uncomment both $dummy assignments,
I get:

   Modification of a read-only value attempted at test.pl line 9.

On the other hand, Damian got a completely different sort of behavior:

> Interestingly, injecting one *extra* lexical declaration anywhere in the
> code (outside the (?{...}) that is) has no effect. But injecting *two*
> lexicals anywhere in the code also stops the match from undefinng $line.
>
> Whereas injecting a second lexical inside the (?{...}) is giving me a
> bus error.

I told Damian I would file this bug and try and answer any questions
(he's in full conference travel mode).

[Please do not change anything below this line]
-----------------------------------------------------------------
---
Flags:
     category=core
     severity=high
---
Site configuration information for perl 5.10.0:

Configured by Message Systems, Inc. at Mon Jan 12 16:03:50 EST 2009.

Summary of my perl5 (revision 5 version 10 subversion 0) configuration:
   Platform:
     osname=linux, osvers=2.6.18-92.1.22.el5, 
archname=x86_64-linux-thread-multi
     uname='linux jpeacock 2.6.18-92.1.22.el5 #1 smp tue dec 16 11:57:43 
est 2008 x86_64 x86_64 x86_64 gnulinux '
     config_args='-des -Uusedtrace -Dmyhostname=localhost 
-Dperladmin=root@localhost -Dcc=/opt/msys/3rdParty/bin/ccache gcc 
-Accflags=-O2 -g -Aldflags= -Alddlflags= -shared -Dcf_by=Message 
Systems, Inc. -Dlibpth=/lib64 /usr/lib64 -Darchname=x86_64-linux 
-Duseshrplib -Di_shadow -Ulocincpth 
-Dlocincpth=/opt/msys/3rdParty/include -Uloclibpth 
-Dloclibpth=/opt/msys/3rdParty/lib -Ui_gdbm -Dusethreads -Duselargefiles 
-Dd_semctl_semun -Di_db -Ui_ndbm -Di_syslog -Dman3ext=3pm 
-Dman1dir=/opt/msys/3rdParty/man/man1 
-Dman3dir=/opt/msys/3rdParty/man/man3 -Duseperlio -Uinstallusrbinperl 
-Ubincompat5005 -Uversiononly -Dpager=/usr/bin/less -isr 
-Dusemultiplicity -Dvendorprefix=/opt/msys -Dprefix=/opt/msys/3rdParty'
     hint=recommended, useposix=true, d_sigaction=define
     useithreads=define, usemultiplicity=define
     useperlio=define, d_sfio=undef, uselargefiles=define, usesocks=undef
     use64bitint=define, use64bitall=define, uselongdouble=undef
     usemymalloc=n, bincompat5005=undef
   Compiler:
     cc='/opt/msys/3rdParty/bin/ccache gcc', ccflags ='-D_REENTRANT 
-D_GNU_SOURCE -O2 -g -fno-strict-aliasing -pipe 
-I/opt/msys/3rdParty/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 
-I/usr/include/gdbm',
     optimize='-O2',
     cppflags='-D_REENTRANT -D_GNU_SOURCE -O2 -g -fno-strict-aliasing 
-pipe -I/opt/msys/3rdParty/include -I/usr/include/gdbm'
     ccversion='', gccversion='4.1.2 20071124 (Red Hat 4.1.2-42)', 
gccosandvers=''
     intsize=4, longsize=8, ptrsize=8, doublesize=8, byteorder=12345678
     d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=16
     ivtype='long', ivsize=8, nvtype='double', nvsize=8, Off_t='off_t', 
lseeksize=8
     alignbytes=8, prototype=define
   Linker and Libraries:
     ld='/opt/msys/3rdParty/bin/ccache gcc', ldflags =' '
     libpth=/lib64 /usr/lib64
     libs=-lnsl -lgdbm -ldl -lm -lcrypt -lutil -lpthread -lc
     perllibs=-lnsl -ldl -lm -lcrypt -lutil -lpthread -lc
     libc=/lib/libc-2.5.so, so=so, useshrplib=true, libperl=libperl.so
     gnulibc_version='2.5'
   Dynamic Linking:
     dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags='-Wl,-E 
-Wl,-rpath,/opt/msys/3rdParty/lib/perl5/5.10.0/x86_64-linux-thread-multi/CORE'
     cccdlflags='-fPIC', lddlflags='  -shared'

Locally applied patches:


---
@INC for perl 5.10.0:
     /opt/msys/3rdParty/lib/perl5/site_perl/5.10.0/x86_64-linux-thread-multi
     /opt/msys/3rdParty/lib/perl5/site_perl/5.10.0
     /opt/msys/lib/perl5/vendor_perl/5.10.0/x86_64-linux-thread-multi
     /opt/msys/lib/perl5/vendor_perl/5.10.0
     /opt/msys/lib/perl5/vendor_perl
     /opt/msys/3rdParty/lib/perl5/5.10.0/x86_64-linux-thread-multi
     /opt/msys/3rdParty/lib/perl5/5.10.0
     .

---
Environment for perl 5.10.0:
     HOME=/home/jpeacock
     LANG=en_US.UTF-8
     LANGUAGE (unset)
     LD_LIBRARY_PATH (unset)
     LOGDIR (unset)
 
PATH=/home/jpeacock/bin:/home/jpeacock/bin:/usr/lib64/qt-3.3/bin:/opt/msys/bin:/usr/kerberos/bin:/usr/local/bin:/usr/bin:/bin:/usr/X11R6/bin:/usr/NX/bin
     PERL_BADLANG (unset)
     SHELL=/bin/bash


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