develooper Front page | perl.perl5.porters | Postings from June 2011

[perl #92696] study called during regex matching can cause wrong matches

Nicholas Clark
June 12, 2011 13:37
[perl #92696] study called during regex matching can cause wrong matches
Message ID:
# New Ticket Created by  Nicholas Clark 
# Please include the string:  [perl #92696]
# in the subject line of all future correspondence about this issue. 
# <URL: >

This is a bug report for perl from,
generated with the help of perlbug 1.39 running under perl 5.15.0.

[Please describe your issue here]

This is correct:

./perl -Ilib -le '$a = "ydydydyd"; $b = "xdx"; warn $_ foreach $a =~ /[^x]d(?{})[^x]d/g'
ydyd at -e line 1.
ydyd at -e line 1.

As are these two:

$ ./perl -Ilib -le '$a = "ydydydyd"; $b = "xdx"; study $a; warn $_ foreach $a =~ /[^x]d(?{})[^x]d/g'
ydyd at -e line 1.
ydyd at -e line 1.
$ ./perl -Ilib -le '$a = "ydydydyd"; $b = "xdx"; study $b; warn $_ foreach $a =~ /[^x]d(?{})[^x]d/g'
ydyd at -e line 1.
ydyd at -e line 1.

Calling study during the match doesn't cause problems if the match target was
not the current studied scalar:

$ ./perl -Ilib -le '$a = "ydydydyd"; $b = "xdx"; warn $_ foreach $a =~ /[^x]d(?{study $b})[^x]d/g'
ydyd at -e line 1.
ydyd at -e line 1.
$ ./perl -Ilib -le '$a = "ydydydyd"; $b = "xdx"; $c = "zz"; study $c; warn $_ foreach $a =~ /[^x]d(?{study $b})[^x]d/g'
ydyd at -e line 1.
ydyd at -e line 1.

however, if study is called during the match, whilst the target is the currently
studied scalar, it goes wrong:

$ ./perl -Ilib -le '$a = "ydydydyd"; $b = "xdx"; study $a; warn $_ foreach $a =~ /[^x]d(?{study $b})[^x]d/g'
ydyd at -e line 1.

[note, just 1 line of output]

The problem is REXEC_SCREAM.

In that, at the start of the match, a flag is set to say "the target is the
currently studied scalar". The tables for the currently studied scalar are
accessed from the interpreter structure, not the currently studied scalar, and
the flag is not cleared on the regex if the currently studied scalar changes,
and hence the tables change.

I think that REXEC_SCREAM is superfluous. The correct state can (I believe)
always be retrieved from SvSCREAM(sv).

Nicholas Clark

[Please do not change anything below this line]
Site configuration information for perl 5.15.0:

Configured by nick at Sun Jun 12 16:47:29 BST 2011.

Summary of my perl5 (revision 5 version 15 subversion 0) configuration:
  Derived from: eeb6b84165f37835a92b974fba01c7e4bbf9fe3f
    osname=darwin, osvers=10.7.0, archname=darwin-2level
    uname='darwin mouse-mill.local 10.7.0 darwin kernel version 10.7.0: sat jan 29 15:17:16 pst 2011; root:xnu-1504.9.37~1release_i386 i386 '
    config_args='-Dusedevel=y -Dcc=ccache gcc-mp-4.6 -Dld=gcc-mp-4.6 -Ubincompat5005 -Uinstallusrbinperl -Dinc_version_list=  -Dinc_version_list_init=0 -Doptimize=-Os -Uusethreads -Uuse64bitall -Uuselongdouble -Uusemymalloc -Duseperlio -Dprefix=~/Sandpit/snap5.9.x-v5.14.0-572-geeb6b84 -Dinstallman1dir=none -Dinstallman3dir=none -Dusevendorprefix -Dvendorprefix=~/Sandpit/vendor -Uuserelocatableinc -Ud_dosuid -Uuseshrplib -de -Accflags=-DNO_MATHOMS -Accccflags=-DNO_PERL_PRESERVE_IVUV -Umad'
    hint=recommended, useposix=true, d_sigaction=define
    useithreads=undef, usemultiplicity=undef
    useperlio=define, d_sfio=undef, uselargefiles=define, usesocks=undef
    use64bitint=define, use64bitall=undef, uselongdouble=undef
    usemymalloc=n, bincompat5005=undef
    cc='ccache gcc-mp-4.6', ccflags ='-fno-common -DPERL_DARWIN -DNO_MATHOMS -fno-strict-aliasing -pipe -fstack-protector -I/opt/local/include',
    cppflags='-fno-common -DPERL_DARWIN -DNO_MATHOMS -fno-strict-aliasing -pipe -fstack-protector -I/opt/local/include'
    ccversion='', gccversion='4.6.1 20110325 (prerelease)', 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='env MACOSX_DEPLOYMENT_TARGET=10.3 cc', ldflags =' -fstack-protector -L/usr/local/lib -L/opt/local/lib'
    libpth=/usr/local/lib /opt/local/lib /usr/lib
    libs=-lgdbm -ldbm -ldl -lm -lutil -lc
    perllibs=-ldl -lm -lutil -lc
    libc=/usr/lib/libc.dylib, so=dylib, useshrplib=false, libperl=libperl.a
  Dynamic Linking:
    dlsrc=dl_dlopen.xs, dlext=bundle, d_dlsymun=undef, ccdlflags=' '
    cccdlflags=' ', lddlflags=' -bundle -undefined dynamic_lookup -L/usr/local/lib -L/opt/local/lib -fstack-protector'

Locally applied patches:

@INC for perl 5.15.0:

Environment for perl 5.15.0:
    LANG (unset)
    LANGUAGE (unset)
    LD_LIBRARY_PATH (unset)
    LOGDIR (unset)
    PERL_BADLANG (unset)
    SHELL=/bin/bash Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About