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

Safe compartments with shared symbols causes Perl debugger to croak #15924

Open
p5pRT opened this issue Mar 17, 2017 · 5 comments
Open

Safe compartments with shared symbols causes Perl debugger to croak #15924

p5pRT opened this issue Mar 17, 2017 · 5 comments

Comments

@p5pRT
Copy link

p5pRT commented Mar 17, 2017

Migrated from rt.perl.org#131013 (status was 'open')

Searchable as RT131013$

@p5pRT
Copy link
Author

p5pRT commented Mar 17, 2017

From @djerius

Created by @djerius

I'm using Perl 5.22.1. Safe 2.39

I'm debugging a program which incidentally runs code in a Safe
compartment. The code executes a subroutine shared from another
package. I'm not interested in the code running in the compartment,
but cannot avoid its execution. The Perl debugger croaks inside the
compartment when the shared subroutine is executed.

Here's test code​:

  use warnings;
  use strict;

  use Safe;

  sub MyPkg​::foo { 33; }

  my $safe= Safe->new;
  $safe->share_from( 'MyPkg', [ '&foo' ] );
  print $safe->reval(q[foo]), "\n";
  print STDERR $@​ if $@​;

When run directly, I get the expected output​:

  % perl tdebug.pl
  33

However, when run under the Perl debugger, the debugger is very unhappy​:

  % perl -d tdebug.pl

  Loading DB routines from perl5db.pl version 1.49
  Editor support available.

  Enter h or 'h h' for help, or 'man perldebug' for more help.

  main​::(tdebug.pl​:8)​: my $safe= Safe->new;
  DB<1> c

  Undefined subroutine &MyPkg​::foo called at [...]/lib/5.22.1/perl5db.pl line 4183.
  Debugged program terminated.

Bug?, feature?, or am I forgetting some special sauce?

Thanks,
Diab

Perl Info

Flags:
    category=utilities
    severity=medium

Site configuration information for perl 5.22.1:

Configured by dj at Wed Feb 10 14:16:03 EST 2016.

Summary of my perl5 (revision 5 version 22 subversion 1) configuration:
   
  Platform:
    osname=linux, osvers=3.2.0-4-amd64, archname=x86_64-linux_debian-7-thread-multi
    uname='linux jeeves 3.2.0-4-amd64 #1 smp debian 3.2.60-1+deb7u3 x86_64 gnulinux '
    config_args='-de -Dprefix=/proj/axaf/ots/pkgs/perl-5.22/x86_64-linux_debian-7 -Uinstallusrbinperl -Dperladmin=none -Dlocincpth=/proj/axaf/ots/include -Darchname=x86_64-linux_debian-7 -Dusethreads -Dotherlibdirs=/proj/axaf/simul/lib/perl5:/proj/axaf/simul/x86_64-linux_debian-7/lib/perl5 -Dloclibpth=/proj/axaf/ots/x86_64-linux_debian-7/lib -Dglibpth=/lib /usr/lib -Dldflags=-L/proj/axaf/ots/x86_64-linux_debian-7/lib -Wl,-rpath=/proj/axaf/ots/x86_64-linux_debian-7/lib -Duseshrplib'
    hint=recommended, useposix=true, d_sigaction=define
    useithreads=define, usemultiplicity=define
    use64bitint=define, use64bitall=define, uselongdouble=undef
    usemymalloc=n, bincompat5005=undef
  Compiler:
    cc='cc', ccflags ='-D_REENTRANT -D_GNU_SOURCE -fwrapv -fno-strict-aliasing -pipe -fstack-protector -I/proj/axaf/ots/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -D_FORTIFY_SOURCE=2',
    optimize='-O2',
    cppflags='-D_REENTRANT -D_GNU_SOURCE -fwrapv -fno-strict-aliasing -pipe -fstack-protector -I/proj/axaf/ots/include'
    ccversion='', gccversion='4.7.2', gccosandvers=''
    intsize=4, longsize=8, ptrsize=8, doublesize=8, byteorder=12345678, doublekind=3
    d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=16, longdblkind=3
    ivtype='long', ivsize=8, nvtype='double', nvsize=8, Off_t='off_t', lseeksize=8
    alignbytes=8, prototype=define
  Linker and Libraries:
    ld='cc', ldflags ='-L/proj/axaf/ots/x86_64-linux_debian-7/lib -Wl,-rpath=/proj/axaf/ots/x86_64-linux_debian-7/lib -fstack-protector'
    libpth=/usr/local/lib /usr/lib/gcc/x86_64-linux-gnu/4.7/include-fixed /usr/include/x86_64-linux-gnu /usr/lib /proj/axaf/ots/x86_64-linux_debian-7/lib /lib/x86_64-linux-gnu /lib/../lib /usr/lib/x86_64-linux-gnu /usr/lib/../lib /lib
    libs=-lpthread -lnsl -lgdbm -ldl -lm -lcrypt -lutil -lc -lgdbm_compat
    perllibs=-lpthread -lnsl -ldl -lm -lcrypt -lutil -lc
    libc=libc-2.13.so, so=so, useshrplib=true, libperl=libperl.so
    gnulibc_version='2.13'
  Dynamic Linking:
    dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags='-Wl,-E -Wl,-rpath,/proj/axaf/ots/pkgs/perl-5.22/x86_64-linux_debian-7/lib/5.22.1/x86_64-linux_debian-7-thread-multi/CORE'
    cccdlflags='-fPIC', lddlflags='-shared -O2 -L/proj/axaf/ots/x86_64-linux_debian-7/lib -fstack-protector'



@INC for perl 5.22.1:
    /proj/axaf/simul/lib/perl5
    /proj/axaf/simul/x86_64-linux_debian-7/lib/perl5/x86_64-linux_debian-7-thread-multi
    /proj/axaf/simul/x86_64-linux_debian-7/lib/perl5
    /home/dj/lib/perl5
    /home/dj/research/lib/perl5
    /home/dj/tmp/lib/perl5/x86_64-linux_debian-7-thread-multi
    /home/dj/tmp/lib/perl5
    /proj/axaf/ots/pkgs/perl-5.22/x86_64-linux_debian-7/lib/site_perl/5.22.1/x86_64-linux_debian-7-thread-multi
    /proj/axaf/ots/pkgs/perl-5.22/x86_64-linux_debian-7/lib/site_perl/5.22.1
    /proj/axaf/ots/pkgs/perl-5.22/x86_64-linux_debian-7/lib/5.22.1/x86_64-linux_debian-7-thread-multi
    /proj/axaf/ots/pkgs/perl-5.22/x86_64-linux_debian-7/lib/5.22.1
    /proj/axaf/simul/lib/perl5
    /proj/axaf/simul/x86_64-linux_debian-7/lib/perl5/x86_64-linux_debian-7-thread-multi
    /proj/axaf/simul/x86_64-linux_debian-7/lib/perl5
    .


Environment for perl 5.22.1:
    HOME=/home/dj
    LANG=en_US.UTF-8
    LANGUAGE (unset)
    LD_LIBRARY_PATH=/soft/SYBASE15.7/DataAccess64/ODBC/lib:/soft/SYBASE15.7/DataAccess/ODBC/lib:/soft/SYBASE15.7/OCS-15_0/lib:/soft/SYBASE15.7/OCS-15_0/lib3p64:/soft/SYBASE15.7/OCS-15_0/lib3p:
    LOGDIR (unset)
    PATH=/home/dj/.plenv/libexec:/home/dj/.plenv/plugins/link-axaf/bin:/home/dj/.plenv/plugins/perl-build/bin:/home/dj/.plenv/plugins/plenv-contrib/bin:/soft/SYBASE15.7/OCS-15_0/bin:/home/dj/.rbenv/shims:/home/dj/.rbenv/bin:/home/dj/.pyenv/plugins/pyenv-virtualenv/shims:/home/dj/.pyenv/shims:/home/dj/.pyenv/bin:/home/dj/.plenv/shims:/home/dj/.plenv/bin:/home/dj/root/bin:/home/dj/root/bin/hosts:/home/dj/root/x86_64-linux_debian-7/bin:/home/dj/research/bin:/proj/axaf/ots/pkgs/perl-5.22/x86_64-linux_debian-7/bin:/proj/axaf/ots/pkgs/gearmand-1.1.12/x86_64-linux_debian-7/sbin:/proj/axaf/bin:/proj/axaf/simul/bin:/proj/axaf/simul/x86_64-linux_debian-7/bin:/proj/axaf/ots/x86_64-linux_debian-7/bin:/proj/axaf/ots/x86_64-linux_debian-7.0/bin:/proj/axaf/ots/bin:/usr/local/bin:/usr/sbin:/bin:/usr/bin:/soft/saord/bin
    PERL5LIB=/proj/axaf/simul/lib/perl5:/proj/axaf/simul/x86_64-linux_debian-7/lib/perl5:/home/dj/lib/perl5:/home/dj/research/lib/perl5:/home/dj/tmp/lib/perl5
    PERL_BADLANG (unset)
    SHELL=/bin/bash

@p5pRT
Copy link
Author

p5pRT commented Sep 30, 2017

From @jkeenan

On Fri, 17 Mar 2017 19​:11​:35 GMT, djerius@​cfa.harvard.edu wrote​:

This is a bug report for perl from djerius@​cfa.harvard.edu,
generated with the help of perlbug 1.40 running under perl 5.22.1.

-----------------------------------------------------------------
[Please describe your issue here]

I'm using Perl 5.22.1. Safe 2.39

I'm debugging a program which incidentally runs code in a Safe
compartment. The code executes a subroutine shared from another
package. I'm not interested in the code running in the compartment,
but cannot avoid its execution. The Perl debugger croaks inside the
compartment when the shared subroutine is executed.

Here's test code​:

use warnings;
use strict;

use Safe;

sub MyPkg​::foo { 33; }

my $safe= Safe->new;
$safe->share_from( 'MyPkg', [ '&foo' ] );
print $safe->reval(q[foo]), "\n";
print STDERR $@​ if $@​;

When run directly, I get the expected output​:

% perl tdebug.pl
33

However, when run under the Perl debugger, the debugger is very
unhappy​:

% perl -d tdebug.pl

Loading DB routines from perl5db.pl version 1.49
Editor support available.

Enter h or 'h h' for help, or 'man perldebug' for more help.

main​::(tdebug.pl​:8)​: my $safe= Safe->new;
DB<1>
c

Undefined subroutine &MyPkg​::foo called at [...]/lib/5.22.1/perl5db.pl
line 4183.
Debugged program terminated.

Bug?, feature?, or am I forgetting some special sauce?

Well, buggy (at the very least).

Note that the program's behavior depends in part upon the context in which $safe->reval('foo') is called.

The attachment, as provided, is pretty much the same as your original post. When I run it through the debugger built on Perl 5 blead, I get​:

#####
  DB<1> c

<Undefined subroutine &MyPkg​::foo called at lib/perl5db.pl line 4214.

Debugged program terminated. Use q to quit or R to restart,
...
#####

I.e., I get a fatal error. The 'print' statement enforces list context.

But suppose that I comment out the 'print' statement, then assign the return value of $safe->reval('foo') to a variable, then print the variable. The call to $safe->reval('foo') is no longer in list context. I now get​:

#####
  DB<1> c
Use of uninitialized value $x in concatenation (.) or string at /home/jkeenan/learn/perl/p5p/131018-safe-debugger.pl line 12.
at /home/jkeenan/learn/perl/p5p/131018-safe-debugger.pl line 12.

Debugged program terminated. Use q to quit or R to restart,
...
#####

I no longer get a fatal error, just an uninitialized value warning.

The plot thickens!

Thank you very much.
--
James E Keenan (jkeenan@​cpan.org)

@p5pRT
Copy link
Author

p5pRT commented Sep 30, 2017

From @jkeenan

131018-safe-debugger.pl

@p5pRT
Copy link
Author

p5pRT commented Sep 30, 2017

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

@p5pRT
Copy link
Author

p5pRT commented Sep 30, 2017

From @jkeenan

On Sat, 30 Sep 2017 23​:36​:33 GMT, jkeenan wrote​:

On Fri, 17 Mar 2017 19​:11​:35 GMT, djerius@​cfa.harvard.edu wrote​:

This is a bug report for perl from djerius@​cfa.harvard.edu,
generated with the help of perlbug 1.40 running under perl 5.22.1.

-----------------------------------------------------------------
[Please describe your issue here]

I'm using Perl 5.22.1. Safe 2.39

I'm debugging a program which incidentally runs code in a Safe
compartment. The code executes a subroutine shared from another
package. I'm not interested in the code running in the compartment,
but cannot avoid its execution. The Perl debugger croaks inside the
compartment when the shared subroutine is executed.

Here's test code​:

use warnings;
use strict;

use Safe;

sub MyPkg​::foo { 33; }

my $safe= Safe->new;
$safe->share_from( 'MyPkg', [ '&foo' ] );
print $safe->reval(q[foo]), "\n";
print STDERR $@​ if $@​;

When run directly, I get the expected output​:

% perl tdebug.pl
33

However, when run under the Perl debugger, the debugger is very
unhappy​:

% perl -d tdebug.pl

Loading DB routines from perl5db.pl version 1.49
Editor support available.

Enter h or 'h h' for help, or 'man perldebug' for more help.

main​::(tdebug.pl​:8)​: my $safe= Safe->new;
DB<1>
c

Undefined subroutine &MyPkg​::foo called at
[...]/lib/5.22.1/perl5db.pl
line 4183.
Debugged program terminated.

Bug?, feature?, or am I forgetting some special sauce?

Well, buggy (at the very least).

Note that the program's behavior depends in part upon the context in
which $safe->reval('foo') is called.

The attachment, as provided, is pretty much the same as your original
post.

Error​: The attachment as provided is the original post modified to demonstrate the non-list-context farther below. To get the program as the OP intended, uncomment the first 'print' statement and comment out the next two lines.

When I run it through the debugger built on Perl 5 blead, I
get​:

#####
DB<1> c

<Undefined subroutine &MyPkg​::foo called at lib/perl5db.pl line 4214.

Debugged program terminated. Use q to quit or R to restart,
...
#####

I.e., I get a fatal error. The 'print' statement enforces list
context.

But suppose that I comment out the 'print' statement, then assign the
return value of $safe->reval('foo') to a variable, then print the
variable. The call to $safe->reval('foo') is no longer in list
context. I now get​:

#####
DB<1> c
Use of uninitialized value $x in concatenation (.) or string at
/home/jkeenan/learn/perl/p5p/131018-safe-debugger.pl line 12.
at /home/jkeenan/learn/perl/p5p/131018-safe-debugger.pl line 12.

Debugged program terminated. Use q to quit or R to restart,
...
#####

I no longer get a fatal error, just an uninitialized value warning.

The plot thickens!

Thank you very much.

--
James E Keenan (jkeenan@​cpan.org)

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

2 participants