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

Opcode module (and thus Safe) think block eval is a string eval #9999

Closed
p5pRT opened this issue Dec 1, 2009 · 5 comments
Closed

Opcode module (and thus Safe) think block eval is a string eval #9999

p5pRT opened this issue Dec 1, 2009 · 5 comments

Comments

@p5pRT
Copy link

p5pRT commented Dec 1, 2009

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

Searchable as RT70970$

@p5pRT
Copy link
Author

p5pRT commented Dec 1, 2009

From @timbunce

  $ perl -Mops=​:default -e 'eval { ; }'
  'eval "string"' trapped by operation mask at -e line 1.

A block eval (entertry opcode) is being treated as a string eval (entereval opcode).

This is a serious problem because most users of Opcode & Safe want to
restrict use of string eval (entereval opcode) but doing so prevents
them using any code/modules that use block eval!

This is true for current blead and at least as far back as 5.8.6.

The bug manifested for me as

  $ perl -Mops=​:default,require /Users/timbo/pg/perl598/lib/5.8.9/Carp.pm
  'eval "string"' trapped by operation mask at /Users/timbo/pg/perl598/lib/5.8.9/Carp.pm line 33.

where line 33 is eval { require Carp​::Heavy };

(Actually the bug manifested while extending PostgreSQL PL/Perl to support the
warnings pragma, but you don't want to know about that.)

(Note that this works​:
  $ perl -Mops=​:default,require -e 'use Carp; warn $INC{"Carp.pm"}'
  /Users/timbo/pg/perl598/lib/5.8.9/Carp.pm at -e line 1.
because Carp was already loaded via ops->Opcode->Carp.)

Using B​::Concise shows an entertry opcode​:

  $ perl -MO=Concise -e 'eval { ; }'
  5 <@​> leave[1 ref] vKP/REFC ->(end)
  1 <0> enter ->2
  2 <;> nextstate(main 2 -e​:1) v ->3
  4 <@​> leavetry vK ->5
  3 <|> entertry(other->4) v ->6
  6 <0> stub v ->4
  -e syntax OK

Using perl -DtxT shows that the entertry started out as a entereval​:

  $ perl -DtxT -e 'eval { ; }' 2>&1
  ### 0​:LEX_NORMAL/XSTATE "\n;"
  ### <== UNIOP(ival=op_entereval)

  ### 1​:LEX_NORMAL/XTERMBLOCK "{ ; }\n"
  ### <== '{'
  ...

In toke.c we have​:

  case KEY_eval​:
  s = SKIPSPACE1(s);
  PL_expect = (*s == '{') ? XTERMBLOCK : XTERM;
  UNIBRACK(OP_ENTEREVAL);

It seems that toke.c should use OP_ENTERTRY instead of OP_ENTEREVAL when
it knows the eval is followed by a block (which it does).

Perl Info

Flags:
    category=core
    severity=high

Site configuration information for perl v5.8.6:

Configured by timbo at Thu May 25 17:26:37 IST 2006.

Summary of my perl5 (revision 5 version 8 subversion 6) configuration:
  Platform:
    osname=darwin, osvers=8.5.2, archname=darwin-thread-multi-2level
    uname='darwin foo 8.5.2 darwin kernel version 8.5.2: mon feb 13 16:31:48 pst 2006; root:xnu-792.8.37.obj~1release_i386 i386 i386 '
    config_args='-des -Dprefix=/usr/local/perl58-i -Doptimize=-g -Duseithreads -Dusemultiplicity'
    hint=recommended, useposix=true, d_sigaction=define
    usethreads=define use5005threads=undef useithreads=define usemultiplicity=define
    useperlio=define d_sfio=undef uselargefiles=define usesocks=undef
    use64bitint=undef use64bitall=undef uselongdouble=undef
    usemymalloc=n, bincompat5005=undef
  Compiler:
    cc='cc', ccflags ='-fno-common -DPERL_DARWIN -no-cpp-precomp -DDEBUGGING -fno-strict-aliasing -pipe -I/usr/local/include -I/opt/local/include',
    optimize='-g',
    cppflags='-no-cpp-precomp -fno-common -DPERL_DARWIN -no-cpp-precomp -DDEBUGGING -fno-strict-aliasing -pipe -I/usr/local/include -I/opt/local/include'
    ccversion='', gccversion='4.0.1 (Apple Computer, Inc. build 5250)', gccosandvers=''
    intsize=4, longsize=4, ptrsize=4, doublesize=8, byteorder=1234
    d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=16
    ivtype='long', ivsize=4, 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 =' -L/usr/local/lib -L/opt/local/lib'
    libpth=/usr/local/lib /opt/local/lib /usr/lib
    libs=-lgdbm -ldbm -ldl -lm -lc
    perllibs=-ldl -lm -lc
    libc=/usr/lib/libc.dylib, so=dylib, useshrplib=false, libperl=libperl.a
    gnulibc_version=''
  Dynamic Linking:
    dlsrc=dl_dyld.xs, dlext=bundle, d_dlsymun=undef, ccdlflags=' '
    cccdlflags=' ', lddlflags=' -bundle -undefined dynamic_lookup -L/usr/local/lib -L/opt/local/lib'

Locally applied patches:
    


@INC for perl v5.8.6:
    /usr/local/perl58-i/lib/5.8.6/darwin-thread-multi-2level
    /usr/local/perl58-i/lib/5.8.6
    /usr/local/perl58-i/lib/site_perl/5.8.6/darwin-thread-multi-2level
    /usr/local/perl58-i/lib/site_perl/5.8.6
    /usr/local/perl58-i/lib/site_perl
    .


Environment for perl v5.8.6:
    HOME=/Users/timbo
    LANG=en_IE.UTF-8
    LANGUAGE (unset)
    LC_ALL=en_IE.UTF-8
    LD_LIBRARY_PATH (unset)
    LOGDIR (unset)
    PERL_BADLANG (unset)
    SHELL=/bin/bash

@p5pRT
Copy link
Author

p5pRT commented Dec 16, 2009

From @timbunce

Any chance someone could take a look at this for 5.12?

I've tried but rapidly went out of my depth (assertion failures etc etc).

Tim.

On Tue, Dec 01, 2009 at 05​:20​:29AM -0800, Tim Bunce wrote​:

$ perl \-Mops=&#8203;:default \-e 'eval \{ ; \}'
'eval "string"' trapped by operation mask at \-e line 1\.

A block eval (entertry opcode) is being treated as a string eval (entereval opcode).

This is a serious problem because most users of Opcode & Safe want to
restrict use of string eval (entereval opcode) but doing so prevents
them using any code/modules that use block eval!

This is true for current blead and at least as far back as 5.8.6.

The bug manifested for me as

$ perl \-Mops=&#8203;:default\,require /Users/timbo/pg/perl598/lib/5\.8\.9/Carp\.pm
'eval "string"' trapped by operation mask at /Users/timbo/pg/perl598/lib/5\.8\.9/Carp\.pm line 33\.

where line 33 is eval { require Carp​::Heavy };

(Actually the bug manifested while extending PostgreSQL PL/Perl to support the
warnings pragma, but you don't want to know about that.)

(Note that this works​:
$ perl -Mops=​:default,require -e 'use Carp; warn $INC{"Carp.pm"}'
/Users/timbo/pg/perl598/lib/5.8.9/Carp.pm at -e line 1.
because Carp was already loaded via ops->Opcode->Carp.)

Using B​::Concise shows an entertry opcode​:

$ perl \-MO=Concise \-e 'eval \{ ; \}'
5  \<@&#8203;> leave\[1 ref\] vKP/REFC \->\(end\)
1     \<0> enter \->2
2     \<;> nextstate\(main 2 \-e&#8203;:1\) v \->3
4     \<@&#8203;> leavetry vK \->5
3        \<|> entertry\(other\->4\) v \->6
6        \<0> stub v \->4
\-e syntax OK

Using perl -DtxT shows that the entertry started out as a entereval​:

$ perl \-DtxT \-e 'eval \{ ; \}' 2>&1
\#\#\# 0&#8203;:LEX\_NORMAL/XSTATE "\\n;"
\#\#\# \<== UNIOP\(ival=op\_entereval\)

\#\#\# 1&#8203;:LEX\_NORMAL/XTERMBLOCK "\{ ; \}\\n"
\#\#\# \<== '\{'
\.\.\.

In toke.c we have​:

    case KEY\_eval&#8203;:
        s = SKIPSPACE1\(s\); 
        PL\_expect = \(\*s == '\{'\) ? XTERMBLOCK : XTERM;
        UNIBRACK\(OP\_ENTEREVAL\);

It seems that toke.c should use OP_ENTERTRY instead of OP_ENTEREVAL when
it knows the eval is followed by a block (which it does).

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

Configured by timbo at Thu May 25 17​:26​:37 IST 2006.

Summary of my perl5 (revision 5 version 8 subversion 6) configuration​:
Platform​:
osname=darwin, osvers=8.5.2, archname=darwin-thread-multi-2level
uname='darwin foo 8.5.2 darwin kernel version 8.5.2​: mon feb 13 16​:31​:48 pst 2006; root​:xnu-792.8.37.obj~1release_i386 i386 i386 '
config_args='-des -Dprefix=/usr/local/perl58-i -Doptimize=-g -Duseithreads -Dusemultiplicity'
hint=recommended, useposix=true, d_sigaction=define
usethreads=define use5005threads=undef useithreads=define usemultiplicity=define
useperlio=define d_sfio=undef uselargefiles=define usesocks=undef
use64bitint=undef use64bitall=undef uselongdouble=undef
usemymalloc=n, bincompat5005=undef
Compiler​:
cc='cc', ccflags ='-fno-common -DPERL_DARWIN -no-cpp-precomp -DDEBUGGING -fno-strict-aliasing -pipe -I/usr/local/include -I/opt/local/include',
optimize='-g',
cppflags='-no-cpp-precomp -fno-common -DPERL_DARWIN -no-cpp-precomp -DDEBUGGING -fno-strict-aliasing -pipe -I/usr/local/include -I/opt/local/include'
ccversion='', gccversion='4.0.1 (Apple Computer, Inc. build 5250)', gccosandvers=''
intsize=4, longsize=4, ptrsize=4, doublesize=8, byteorder=1234
d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=16
ivtype='long', ivsize=4, 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 =' -L/usr/local/lib -L/opt/local/lib'
libpth=/usr/local/lib /opt/local/lib /usr/lib
libs=-lgdbm -ldbm -ldl -lm -lc
perllibs=-ldl -lm -lc
libc=/usr/lib/libc.dylib, so=dylib, useshrplib=false, libperl=libperl.a
gnulibc_version=''
Dynamic Linking​:
dlsrc=dl_dyld.xs, dlext=bundle, d_dlsymun=undef, ccdlflags=' '
cccdlflags=' ', lddlflags=' -bundle -undefined dynamic_lookup -L/usr/local/lib -L/opt/local/lib'

Locally applied patches​:

---
@​INC for perl v5.8.6​:
/usr/local/perl58-i/lib/5.8.6/darwin-thread-multi-2level
/usr/local/perl58-i/lib/5.8.6
/usr/local/perl58-i/lib/site_perl/5.8.6/darwin-thread-multi-2level
/usr/local/perl58-i/lib/site_perl/5.8.6
/usr/local/perl58-i/lib/site_perl
.

---
Environment for perl v5.8.6​:
HOME=/Users/timbo
LANG=en_IE.UTF-8
LANGUAGE (unset)
LC_ALL=en_IE.UTF-8
LD_LIBRARY_PATH (unset)
LOGDIR (unset)
PERL_BADLANG (unset)
SHELL=/bin/bash

@p5pRT
Copy link
Author

p5pRT commented Dec 20, 2009

From @rgarcia

2009/12/1 Tim Bunce <perlbug-followup@​perl.org>​:

   $ perl -Mops=​:default -e 'eval { ; }'
   'eval "string"' trapped by operation mask at -e line 1.

A block eval (entertry opcode) is being treated as a string eval (entereval opcode).

This is a serious problem because most users of Opcode & Safe want to
restrict use of string eval (entereval opcode) but doing so prevents
them using any code/modules that use block eval!

This should be fixed by commit 32e2a35.
Note that this is a core bug, not a Safe/ops bug​: it's not possible to
backport it to older perls.

@p5pRT
Copy link
Author

p5pRT commented Dec 20, 2009

The RT System itself - Status changed from 'new' to 'open'

@p5pRT
Copy link
Author

p5pRT commented Dec 20, 2009

@rgs - Status changed from 'open' 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