Skip to content

crash in return from lvalue subroutine from try {} block #18553

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

Closed
tonycoz opened this issue Feb 9, 2021 · 4 comments
Closed

crash in return from lvalue subroutine from try {} block #18553

tonycoz opened this issue Feb 9, 2021 · 4 comments

Comments

@tonycoz
Copy link
Contributor

tonycoz commented Feb 9, 2021

Module:

Description

I was looking again over the pp_return code in reference to #18540, and while I don't see an ordering problem, I do think that the additional code that's doing what dopopto_cursub() should be doing is a bit suspicious.

I looked over what else calls dopopto_cursub(), and ended up with:

$ gdb --args ./perl -Ilib -Mfeature=try -le 'my $x = 0; sub foo :lvalue { try { print "Hello\n"; return %x } catch ($e) { } } foo() = 1; print $x'
...
(gdb) r
Starting program: /home/tony/dev/perl/git/perl4/perl -Ilib -Mfeature=try -le my\ \$x\ =\ 0\;\ sub\ foo\ :lvalue\ \{\ try\ \{\ print\ \"Hello\\n\"\;\ return\ %x\ \}\ catch\ \(\$e\)\ \{\ \}\ \}\ foo\(\)\ =\ 1\;\ print\ \$x
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
try/catch is experimental at -e line 1.
try/catch is experimental at -e line 1.
Hello


Program received signal SIGSEGV, Segmentation fault.
0x00005555558440e9 in Perl_is_lvalue_sub () at pp_ctl.c:1416
1416        if (CxLVAL(cxstack + cxix) && CvLVALUE(cxstack[cxix].blk_sub.cv))
(gdb) bt
#0  0x00005555558440e9 in Perl_is_lvalue_sub () at pp_ctl.c:1416
#1  0x000055555577c005 in Perl_pp_rv2av () at pp_hot.c:1980
#2  0x0000555555721e8d in Perl_runops_debug () at dump.c:2572
#3  0x00005555555f1102 in S_run_body (oldscope=1) at perl.c:2743
#4  0x00005555555f0680 in perl_run (my_perl=0x555555c17260) at perl.c:2666
#5  0x00005555555a2122 in main (argc=5, argv=0x7fffffffe778, 
    env=0x7fffffffe7a8) at perlmain.c:110

I haven't worked out a fix yet, I don't see the segv with #18552 but I don't see anything in that change which I'd expect to fix this problem either.

Steps to Reproduce

see above

Expected behavior

don't crash

Perl configuration

tony@venus:.../git/perl4$ ./perl -Ilib -V
Summary of my perl5 (revision 5 version 33 subversion 7) configuration:
  Commit id: 44898a56694f929002276127c878850373a82481
  Platform:
    osname=linux
    osvers=4.19.0-13-amd64
    archname=x86_64-linux
    uname='linux venus 4.19.0-13-amd64 #1 smp debian 4.19.160-2 (2020-11-28) x86_64 gnulinux '
    config_args='-des -Dusedevel -DDEBUGGING -Doptimize=-O0 -g'
    hint=recommended
    useposix=true
    d_sigaction=define
    useithreads=undef
    usemultiplicity=undef
    use64bitint=define
    use64bitall=define
    uselongdouble=undef
    usemymalloc=n
    default_inc_excludes_dot=define
  Compiler:
    cc='cc'
    ccflags ='-fwrapv -DDEBUGGING -fno-strict-aliasing -pipe -fstack-protector-strong -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -D_FORTIFY_SOURCE=2'
    optimize='-O0 -g'
    cppflags='-fwrapv -DDEBUGGING -fno-strict-aliasing -pipe -fstack-protector-strong -I/usr/local/include'
    ccversion=''
    gccversion='8.3.0'
    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 =' -fstack-protector-strong -L/usr/local/lib'
    libpth=/usr/local/lib /usr/lib/gcc/x86_64-linux-gnu/8/include-fixed /usr/include/x86_64-linux-gnu /usr/lib /lib/x86_64-linux-gnu /lib/../lib /usr/lib/x86_64-linux-gnu /usr/lib/../lib /lib /lib64 /usr/lib64
    libs=-lpthread -lnsl -lgdbm -ldl -lm -lcrypt -lutil -lc
    perllibs=-lpthread -lnsl -ldl -lm -lcrypt -lutil -lc
    libc=libc-2.28.so
    so=so
    useshrplib=false
    libperl=libperl.a
    gnulibc_version='2.28'
  Dynamic Linking:
    dlsrc=dl_dlopen.xs
    dlext=so
    d_dlsymun=undef
    ccdlflags='-Wl,-E'
    cccdlflags='-fPIC'
    lddlflags='-shared -O0 -g -L/usr/local/lib -fstack-protector-strong'


Characteristics of this binary (from libperl): 
  Compile-time options:
    DEBUGGING
    HAS_TIMES
    PERLIO_LAYERS
    PERL_COPY_ON_WRITE
    PERL_DONT_CREATE_GVSV
    PERL_MALLOC_WRAP
    PERL_OP_PARENT
    PERL_PRESERVE_IVUV
    PERL_USE_DEVEL
    USE_64_BIT_ALL
    USE_64_BIT_INT
    USE_LARGE_FILES
    USE_LOCALE
    USE_LOCALE_COLLATE
    USE_LOCALE_CTYPE
    USE_LOCALE_NUMERIC
    USE_LOCALE_TIME
    USE_PERLIO
    USE_PERL_ATOF
  Built under linux
  Compiled at Feb 10 2021 09:50:07
  %ENV:
    PERLBREW_BASHRC_VERSION="0.43"
    PERLBREW_HOME="/home/tony/.perlbrew"
    PERLBREW_MANPATH=""
    PERLBREW_PATH="/home/tony/perl5/perlbrew/bin"
    PERLBREW_ROOT="/home/tony/perl5/perlbrew"
    PERLBREW_VERSION="0.67"
  @INC:
    lib
    /usr/local/lib/perl5/site_perl/5.33.7/x86_64-linux
    /usr/local/lib/perl5/site_perl/5.33.7
    /usr/local/lib/perl5/5.33.7/x86_64-linux
    /usr/local/lib/perl5/5.33.7
@tonycoz
Copy link
Contributor Author

tonycoz commented Feb 9, 2021

There's still some misbehaviour even with #18552:

tony@venus:.../git/perl4$ ./perl -Ilib -Mfeature=try -le 'my @x = 0; sub foo :lvalue { print "Hello\n"; return @x} (foo()) = (1, 2); print @x'
Hello

12
tony@venus:.../git/perl4$ ./perl -Ilib -Mfeature=try -le 'my @x = 0; sub foo :lvalue { try { print "Hello\n"; return @x } catch ($e) {}} (foo()) = (1, 2); print @x'
try/catch is experimental at -e line 1.
try/catch is experimental at -e line 1.
Hello

1

@leonerd
Copy link
Contributor

leonerd commented Feb 10, 2021

Having now merged your commit (3ab1cbe) in, I now get a consistent output:

$ ./perl -Ilib -Mfeature=try -le 'my @x = 0; sub foo :lvalue { try { print "Hello\n"; return @x } catch ($e) {}} (foo()) = (1, 2); print @x'
try/catch is experimental at -e line 1.
try/catch is experimental at -e line 1.
Hello

12

@leonerd
Copy link
Contributor

leonerd commented Feb 10, 2021

A unit test for this case is now added in #18552

@xenu
Copy link
Member

xenu commented Oct 20, 2021

According to the comments in this ticket, the issue is resolved.

@xenu xenu closed this as completed Oct 20, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants