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

$SIG{__DIE__} + goto -> infinite recursion & segfault #14990

Open
p5pRT opened this issue Oct 16, 2015 · 3 comments
Open

$SIG{__DIE__} + goto -> infinite recursion & segfault #14990

p5pRT opened this issue Oct 16, 2015 · 3 comments

Comments

@p5pRT
Copy link

p5pRT commented Oct 16, 2015

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

Searchable as RT126376$

@p5pRT
Copy link
Author

p5pRT commented Oct 16, 2015

From @FGasper

Created by @FGasper

----------------------------------------------------------------------
#!/usr/bin/perl

use strict;
use warnings;

syswrite \*STDOUT, "start!\n";

$SIG{'__DIE__'} = sub {
  goto \&_rethrow;
};

sub _rethrow {
  syswrite \*STDOUT, "rethrow​: @​_";
  die @​_;
}

die 'mayhem!';
----------------------------------------------------------------------

^^ Run the above code, and watch it segfault. It happens on all
perls from 5.8 to 5.22.

This should not (?) happen per "perldoc perlvar", which says
that $SIG{__DIE__} is disabled within a __DIE__ handler. The goto()
appears to be throwing that off, though.

Perl Info

Flags:
    category=core
    severity=medium

This perlbug was built using Perl 5.10.1 in the Fedora build system.
It is being executed now by Perl 5.10.1 - Sun Nov  6 00:37:43 GMT 2011.

Site configuration information for perl 5.10.1:

Configured by Red Hat, Inc. at Sun Nov  6 00:37:43 GMT 2011.

Summary of my perl5 (revision 5 version 10 subversion 1) configuration:
   
  Platform:
    osname=linux, osvers=2.6.32-44.2.el6.x86_64, archname=x86_64-linux-thread-multi
    uname='linux c6b5.bsys.dev.centos.org 2.6.32-44.2.el6.x86_64 #1 smp wed jul 21 12:48:32 edt 2010 x86_64 x86_64 x86_64 gnulinux '
    config_args='-des -Doptimize=-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64 -mtune=generic -DDEBUGGING=-g -Dversion=5.10.1 -Dmyhostname=localhost -Dperladmin=root@localhost -Dcc=gcc -Dcf_by=Red Hat, Inc. -Dprefix=/usr -Dvendorprefix=/usr -Dsiteprefix=/usr/local -Dsitelib=/usr/local/share/perl5 -Dsitearch=/usr/local/lib64/perl5 -Dprivlib=/usr/share/perl5 -Darchlib=/usr/lib64/perl5 -Dvendorlib=/usr/share/perl5/vendor_perl -Dvendorarch=/usr/lib64/perl5/vendor_perl -Dinc_version_list=5.10.0 -Darchname=x86_64-linux-thread-multi -Dlibpth=/usr/local/lib64 /lib64 /usr/lib64 -Duseshrplib -Dusethreads -Duseithreads -Duselargefiles -Dd_dosuid -Dd_semctl_semun -Di_db -Ui_ndbm -Di_gdbm -Di_shadow -Di_syslog -Dman3ext=3pm -Duseperlio -Dinstallusrbinperl=n -Ubincompat5005 -Uversiononly -Dpager=/usr/bin/less -isr -Dd_gethostent_r_proto -Ud_endhostent_r_proto -Ud_sethostent_r_proto -Ud_endprotoent_r_proto -Ud_setprotoent_r_proto -Ud_endservent_r_proto -Ud_setservent_r_proto -Dscriptdir=/usr/bin'
    hint=recommended, useposix=true, d_sigaction=define
    useithreads=define, usemultiplicity=define
    useperlio=define, d_sfio=undef, uselargefiles=define, usesocks=undef
    use64bitint=define, use64bitall=define, uselongdouble=undef
    usemymalloc=n, bincompat5005=undef
  Compiler:
    cc='gcc', ccflags ='-D_REENTRANT -D_GNU_SOURCE -fno-strict-aliasing -pipe -fstack-protector -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64',
    optimize='-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64 -mtune=generic',
    cppflags='-D_REENTRANT -D_GNU_SOURCE -fno-strict-aliasing -pipe -fstack-protector -I/usr/local/include'
    ccversion='', gccversion='4.4.5 20110214 (Red Hat 4.4.5-6)', 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='gcc', ldflags =' -fstack-protector'
    libpth=/usr/local/lib64 /lib64 /usr/lib64
    libs=-lresolv -lnsl -lgdbm -ldb -ldl -lm -lcrypt -lutil -lpthread -lc
    perllibs=-lresolv -lnsl -ldl -lm -lcrypt -lutil -lpthread -lc
    libc=, so=so, useshrplib=true, libperl=libperl.so
    gnulibc_version='2.12'
  Dynamic Linking:
    dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags='-Wl,-E -Wl,-rpath,/usr/lib64/perl5/CORE'
    cccdlflags='-fPIC', lddlflags='-shared -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64 -mtune=generic'

Locally applied patches:
    


@INC for perl 5.10.1:
    /home/fgasper/perl5/lib/perl5
    /home/fgasper/perl5/lib/perl5/x86_64-linux-thread-multi
    /home/fgasper/perl/home/fgasper/perl5/lib/perl5/x86_64-linux-thread-multi
    /home/fgasper/perl/home/fgasper/perl5/lib/perl5
    /home/fgasper/perl/usr/local/lib64/perl5
    /home/fgasper/perl/usr/local/share/perl5
    /home/fgasper/perl/usr/lib64/perl5/vendor_perl
    /home/fgasper/perl/usr/share/perl5/vendor_perl
    /home/fgasper/perl/usr/lib64/perl5
    /home/fgasper/perl/usr/share/perl5
    /home/fgasper/perl5/lib/perl5/x86_64-linux-thread-multi
    /home/fgasper/perl5/lib/perl5
    /usr/local/lib64/perl5
    /usr/local/share/perl5
    /usr/lib64/perl5/vendor_perl
    /usr/share/perl5/vendor_perl
    /usr/lib64/perl5
    /usr/share/perl5
    .


Environment for perl 5.10.1:
    HOME=/home/fgasper
    LANG (unset)
    LANGUAGE (unset)
    LD_LIBRARY_PATH (unset)
    LOGDIR (unset)
    PATH=/home/fgasper/perl5/bin:/usr/local/jdk/bin:/usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11R6/bin:/opt/dell/srvadmin/bin:/usr/local/cpanel/3rdparty/bin:/home/fgasper/bin
    PERL5LIB=/home/fgasper/perl5/lib/perl5
    PERL_BADLANG (unset)
    PERL_LOCAL_LIB_ROOT=/home/fgasper/perl5
    PERL_MB_OPT=--install_base "/home/fgasper/perl5"
    PERL_MM_OPT=INSTALL_BASE=/home/fgasper/perl5
    SHELL=/bin/bash

@p5pRT
Copy link
Author

p5pRT commented Oct 21, 2015

From @tonycoz

On Fri Oct 16 12​:38​:18 2015, felipe@​felipegasper.com wrote​:

^^ Run the above code, and watch it segfault. It happens on all
perls from 5.8 to 5.22.

This should not (?) happen per "perldoc perlvar", which says
that $SIG{__DIE__} is disabled within a __DIE__ handler. The goto()
appears to be throwing that off, though.

goto &foo is one of the documented ways of exiting the __DIE__ handler, but it doesn't seem to be behaving as documented​:

  When a C<__DIE__> hook routine returns, the exception
processing continues as it would have in the absence of the hook,
unless the hook routine itself exits via a C<goto &sub>, a loop exit,
or a C<die()>.

The seg fault is due to running out of stack space from deep recursion.

As to the recursion, the code checks whether the CV for the __DIE__ handler is running (with CvDEPTH()), which it isn't after goto &_rethrow.

Tony

@p5pRT
Copy link
Author

p5pRT commented Oct 21, 2015

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

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