Skip Menu |

Subject: perl5db.pl does not set new filehandles into ReadLine after pager command
To: perlbug [...] perl.org
Date: Tue, 18 Mar 2014 02:01:48 +0900
From: 林宏雄 <hiroo.hayashi [...] computer.org>
Download (untitled) / with headers
text/plain 5.9k
This is a bug report for perl from hiroo.hayashi@computer.org,
generated with the help of perlbug 1.39 running under perl 5.16.3.


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

perl5db.pl does not set new file-handles into ReadLine after pager
command.  This cause a segmentation fault when used with
Term::ReadLine::Gnu.
See https://rt.cpan.org/Public/Bug/Display.html?id=83040 for more details.

When the pager command (| or ||) is used in perldb, it overwrites the OUT file
handle. perldb.pl has a function, reset_IN_OUT(), for such case, but
it is not called after the pager command.

From http://search.cpan.org/~rjbs/perl-5.18.2/lib/perl5db.pl#reset_IN_OUT
-----------------------
reset_IN_OUT
This routine handles restoring the debugger's input and output
file-handles after we've tried and failed to move them elsewhere. In
addition, it assigns the debugger's output file-handle to $LINEINFO if
it was already open there.
-----------------------

In reset_IN_OUT() Term::ReadLine:newTTY() is called.

The perl implementations of Term::ReadLine (Term::ReadLine::Stub or
Term::ReadLine::Perl, etc.) are not affected by this bug, because the OUT file
handle is in the global scope.  But for XS implementation needs newTTY() to
be called.

Attached are the patches for
  perldb5 version 1.43 in perl 5.19.9 (latest development release)
  perldb5 version 1.39_10 in perl 5.18.2 (latest stable)
  perldb5 version 1.37 in perl 5.16.3 (previous stable)

[Please do not change anything below this line]
-----------------------------------------------------------------
---
Flags:
    category=utilities
    severity=medium
---
Site configuration information for perl 5.16.3:

Configured by Red Hat, Inc. at Mon Nov 11 12:49:48 UTC 2013.

Summary of my perl5 (revision 5 version 16 subversion 3) configuration:
  
  Platform:
    osname=linux, osvers=3.10.9-200.fc19.x86_64, archname=x86_64-linux-thread-multi
    uname='linux buildvm-04.phx2.fedoraproject.org 3.10.9-200.fc19.x86_64 #1 smp wed aug 21 19:27:58 utc 2013 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 -Dccdlflags=-Wl,--enable-new-dtags -Dlddlflags=-shared -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4  -m64 -mtune=generic -Wl,-z,relro  -DDEBUGGING=-g -Dversion=5.16.3 -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 -Dvendorlib=/usr/share/perl5/vendor_perl -Darchlib=/usr/lib64/perl5 -Dvendorarch=/usr/lib64/perl5/vendor_perl -Darchname=x86_64-linux-thread-multi -Dlibpth=/usr/local/lib64 /lib64 /usr/lib64 -Duseshrplib -Dusethreads -Duseithreads -Dusedtrace=/usr/bin/dtrace -Duselargefiles -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 -Dusesitecustomize'
    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.7.2 20121109 (Red Hat 4.7.2-8)', 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 -lgdbm_compat
    perllibs=-lresolv -lnsl -ldl -lm -lcrypt -lutil -lpthread -lc
    libc=, so=so, useshrplib=true, libperl=libperl.so
    gnulibc_version='2.16'
  Dynamic Linking:
    dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags='-Wl,--enable-new-dtags -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 -Wl,-z,relro '

Locally applied patches:
   

---
@INC for perl 5.16.3:
    /home/hiroo/perl5/lib/perl5/x86_64-linux-thread-multi
    /home/hiroo/perl5/lib/perl5
    /home/hiroo/perl5/lib/perl5/x86_64-linux-thread-multi
    /home/hiroo/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.16.3:
    HOME=/home/hiroo
    LANG=en_US.utf8
    LANGUAGE (unset)
    LD_LIBRARY_PATH (unset)
    LOGDIR (unset)
    PATH=/home/hiroo/perl5/bin:/home/hiroo/perl5/bin:/usr/local/bin:/usr/bin:/bin:/usr/local/sbin:/usr/sbin:/home/hiroo/.local/bin:/home/hiroo/bin
    PERL5LIB=/home/hiroo/perl5/lib/perl5:/home/hiroo/perl5/lib/perl5:
    PERL_BADLANG (unset)
    PERL_LOCAL_LIB_ROOT=:/home/hiroo/perl5:/home/hiroo/perl5
    PERL_MB_OPT=--install_base /home/hiroo/perl5
    PERL_MM_OPT=INSTALL_BASE=/home/hiroo/perl5
    SHELL=/bin/bash


--
Hiroo Hayashi

Message body is not shown because sender requested not to inline it.

Message body is not shown because sender requested not to inline it.

Message body is not shown because sender requested not to inline it.

RT-Send-CC: perl5-porters [...] perl.org
Download (untitled) / with headers
text/plain 6.8k
Hi all, On Mon Mar 17 10:02:01 2014, hiroo.hayashi@computer.org wrote: Show quoted text
> This is a bug report for perl from hiroo.hayashi@computer.org, > generated with the help of perlbug 1.39 running under perl 5.16.3. > > > ----------------------------------------------------------------- > [Please describe your issue here] > > perl5db.pl does not set new file-handles into ReadLine after pager > command. This cause a segmentation fault when used with > Term::ReadLine::Gnu. > See https://rt.cpan.org/Public/Bug/Display.html?id=83040 for more > details. > > When the pager command (| or ||) is used in perldb, it overwrites the > OUT > file > handle. perldb.pl has a function, reset_IN_OUT(), for such case, but > it is not called after the pager command. > > From http://search.cpan.org/~rjbs/perl- > 5.18.2/lib/perl5db.pl#reset_IN_OUT > ----------------------- > reset_IN_OUT > This routine handles restoring the debugger's input and output > file-handles after we've tried and failed to move them elsewhere. In > addition, it assigns the debugger's output file-handle to $LINEINFO if > it was already open there. > ----------------------- > > In reset_IN_OUT() Term::ReadLine:newTTY() is called. > > The perl implementations of Term::ReadLine (Term::ReadLine::Stub or > Term::ReadLine::Perl, etc.) are not affected by this bug, because the > OUT > file > handle is in the global scope. But for XS implementation needs > newTTY() to > be called. > > Attached are the patches for > perldb5 version 1.43 in perl 5.19.9 (latest development release) > perldb5 version 1.39_10 in perl 5.18.2 (latest stable) > perldb5 version 1.37 in perl 5.16.3 (previous stable) >
Thanks for the investigation and the fix. I tested it in bleadperl and it indeed fixed the problem (which also bothered me, but I lacked the tuits to fix it). That put aside, I have reworked the bleadperl patch a little to: 1. Fix the grammar in the comment a little. 2. Fix the indentation from tabs-based to be consistently space-based. That patch is attached here and I'm planning to also work on similar patches for maintperl-5.18.x and maintperl-5.16.x. Note that the cmp_version.t core test fails with it - perhaps the $VERSION in perl5db.pl needs to be updated. Regards, -- Shlomi Fish Show quoted text
> [Please do not change anything below this line] > ----------------------------------------------------------------- > --- > Flags: > category=utilities > severity=medium > --- > Site configuration information for perl 5.16.3: > > Configured by Red Hat, Inc. at Mon Nov 11 12:49:48 UTC 2013. > > Summary of my perl5 (revision 5 version 16 subversion 3) > configuration: > > Platform: > osname=linux, osvers=3.10.9-200.fc19.x86_64, > archname=x86_64-linux-thread-multi > uname='linux buildvm-04.phx2.fedoraproject.org 3.10.9- > 200.fc19.x86_64 > #1 smp wed aug 21 19:27:58 utc 2013 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 -Dccdlflags=-Wl,--enable-new-dtags -Dlddlflags=-shared > -O2 > -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector > --param=ssp-buffer-size=4 -m64 -mtune=generic -Wl,-z,relro > -DDEBUGGING=-g > -Dversion=5.16.3 -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 > -Dvendorlib=/usr/share/perl5/vendor_perl -Darchlib=/usr/lib64/perl5 > -Dvendorarch=/usr/lib64/perl5/vendor_perl > -Darchname=x86_64-linux-thread-multi -Dlibpth=/usr/local/lib64 /lib64 > /usr/lib64 -Duseshrplib -Dusethreads -Duseithreads > -Dusedtrace=/usr/bin/dtrace -Duselargefiles -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 -Dusesitecustomize' > 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.7.2 20121109 (Red Hat 4.7.2-8)', > 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 > -lgdbm_compat > perllibs=-lresolv -lnsl -ldl -lm -lcrypt -lutil -lpthread -lc > libc=, so=so, useshrplib=true, libperl=libperl.so > gnulibc_version='2.16' > Dynamic Linking: > dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, > ccdlflags='-Wl,--enable-new-dtags -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 -Wl,-z,relro ' > > Locally applied patches: > > > --- > @INC for perl 5.16.3: > /home/hiroo/perl5/lib/perl5/x86_64-linux-thread-multi > /home/hiroo/perl5/lib/perl5 > /home/hiroo/perl5/lib/perl5/x86_64-linux-thread-multi > /home/hiroo/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.16.3: > HOME=/home/hiroo > LANG=en_US.utf8 > LANGUAGE (unset) > LD_LIBRARY_PATH (unset) > LOGDIR (unset) > > PATH=/home/hiroo/perl5/bin:/home/hiroo/perl5/bin:/usr/local/bin:/usr/bin:/bin:/usr/local/sbin:/usr/sbin:/home/hiroo/.local/bin:/home/hiroo/bin > PERL5LIB=/home/hiroo/perl5/lib/perl5:/home/hiroo/perl5/lib/perl5: > PERL_BADLANG (unset) > PERL_LOCAL_LIB_ROOT=:/home/hiroo/perl5:/home/hiroo/perl5 > PERL_MB_OPT=--install_base /home/hiroo/perl5 > PERL_MM_OPT=INSTALL_BASE=/home/hiroo/perl5 > SHELL=/bin/bash
Subject: perl5db-bleadperl-Term-RL-Gnu-pager-crash.patch
diff --git a/lib/perl5db.pl b/lib/perl5db.pl index c1d6752..ae04a9a 100644 --- a/lib/perl5db.pl +++ b/lib/perl5db.pl @@ -2419,6 +2419,9 @@ sub _DB__at_end_of_every_command { open( OUT, ">&SAVEOUT" ) || _db_warn("Can't restore DB::OUT"); } + # Let Readline know about the new filehandles. + reset_IN_OUT( \*IN, \*OUT ); + # Close filehandle pager was using, restore the normal one # if necessary, close(SAVEOUT);
RT-Send-CC: perl5-porters [...] perl.org
Download (untitled) / with headers
text/plain 232b
Hi, replying to myself, I'm attaching the corresponding patches for maint5.18 and maint5.16 (which I tested to see that the bug is fixed). Please also credit Hiroo Hayashi as an originator of these patch. Regards, -- Shlomi Fish
Subject: perl5db-maint5.16-Term-RL-Gnu-pager-crash.patch
diff --git a/lib/perl5db.pl b/lib/perl5db.pl index 889f305..29bf740 100644 --- a/lib/perl5db.pl +++ b/lib/perl5db.pl @@ -3316,6 +3316,9 @@ our standard filehandles for input and output. open( OUT, ">&SAVEOUT" ) || &warn("Can't restore DB::OUT"); } + # Let Readline know about the new filehandles. + reset_IN_OUT( \*IN, \*OUT ); + # Close filehandle pager was using, restore the normal one # if necessary, close(SAVEOUT);
Subject: perl5db-maint5.18-Term-RL-Gnu-pager-crash.patch
diff --git a/lib/perl5db.pl b/lib/perl5db.pl index da532fb..c2921d7 100644 --- a/lib/perl5db.pl +++ b/lib/perl5db.pl @@ -2418,6 +2418,9 @@ sub _DB__at_end_of_every_command { open( OUT, ">&SAVEOUT" ) || _db_warn("Can't restore DB::OUT"); } + # Let Readline know about the new filehandles. + reset_IN_OUT( \*IN, \*OUT ); + # Close filehandle pager was using, restore the normal one # if necessary, close(SAVEOUT);
RT-Send-CC: perl5-porters [...] perl.org
Download (untitled) / with headers
text/plain 120b
This has been applied to 5.19, and I've marked it as blocking the 5.16 and 5.18 maint branches' next releases. -- rjbs
RT-Send-CC: perl5-porters [...] perl.org
Download (untitled) / with headers
text/plain 190b
On Mon Apr 07 07:59:57 2014, rjbs wrote: Show quoted text
> This has been applied to 5.19, and I've marked it as blocking the 5.16 > and 5.18 maint branches' next releases.
+1 for maint 5.18 and 5.16. Tony
To: perlbug-followup [...] perl.org, "OtherRecipients of perl Ticket #121456:;" [...] smtp.indra.com
Date: Tue, 15 Apr 2014 22:08:53 -0600
Subject: Re: [perl #121456] perl5db.pl does not set new filehandles into ReadLine after pager command
CC: perl5-porters [...] perl.org
From: Karl Williamson <public [...] khwilliamson.com>
Download (untitled) / with headers
text/plain 366b
On 04/15/2014 09:24 PM, Tony Cook via RT wrote: Show quoted text
> On Mon Apr 07 07:59:57 2014, rjbs wrote:
>> This has been applied to 5.19, and I've marked it as blocking the 5.16 >> and 5.18 maint branches' next releases.
> > +1 for maint 5.18 and 5.16. > > Tony > > --- > via perlbug: queue: perl5 status: open > https://rt.perl.org/Ticket/Display.html?id=121456 >
+1 to both


This service is sponsored and maintained by Best Practical Solutions and runs on Perl.org infrastructure.

For issues related to this RT instance (aka "perlbug"), please contact perlbug-admin at perl.org