Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

study called during regex matching can cause wrong matches #11436

Closed
p5pRT opened this issue Jun 12, 2011 · 2 comments
Closed

study called during regex matching can cause wrong matches #11436

p5pRT opened this issue Jun 12, 2011 · 2 comments

Comments

@p5pRT
Copy link

p5pRT commented Jun 12, 2011

Migrated from rt.perl.org#92696 (status was 'resolved')

Searchable as RT92696$

@p5pRT
Copy link
Author

p5pRT commented Jun 12, 2011

From @nwc10

Created by @nwc10

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

Perl Info

Flags:
    category=core
    severity=low

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
  Platform:
    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 -Dcf_email=nick@ccl4.org -Dperladmin=nick@ccl4.org -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
  Compiler:
    cc='ccache gcc-mp-4.6', ccflags ='-fno-common -DPERL_DARWIN -DNO_MATHOMS -fno-strict-aliasing -pipe -fstack-protector -I/opt/local/include',
    optimize='-Os',
    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
    gnulibc_version=''
  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:
    lib
    /Users/nick/Sandpit/snap5.9.x-v5.14.0-572-geeb6b84/lib/perl5/site_perl/5.15.0/darwin-2level
    /Users/nick/Sandpit/snap5.9.x-v5.14.0-572-geeb6b84/lib/perl5/site_perl/5.15.0
    /Users/nick/Sandpit/vendor/lib/perl5/vendor_perl/5.15.0/darwin-2level
    /Users/nick/Sandpit/vendor/lib/perl5/vendor_perl/5.15.0
    /Users/nick/Sandpit/snap5.9.x-v5.14.0-572-geeb6b84/lib/perl5/5.15.0/darwin-2level
    /Users/nick/Sandpit/snap5.9.x-v5.14.0-572-geeb6b84/lib/perl5/5.15.0
    .


Environment for perl 5.15.0:
    DYLD_LIBRARY_PATH (unset)
    HOME=/Users/nick
    LANG (unset)
    LANGUAGE (unset)
    LD_LIBRARY_PATH (unset)
    LOGDIR (unset)
    PATH=/opt/local/bin:/opt/local/sbin:/opt/local/bin:/opt/local/sbin:/Users/nick/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin:/usr/local/sbin:/sbin:/usr/sbin
    PERL_BADLANG (unset)
    SHELL=/bin/bash

@p5pRT
Copy link
Author

p5pRT commented Jun 30, 2011

@nwc10 - Status changed from 'new' to 'resolved'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant