Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 94810 - perl which uses Term::ReadLine segfaults on process exit; glibc double-free
Summary: perl which uses Term::ReadLine segfaults on process exit; glibc double-free
Status: RESOLVED INVALID
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: [OLD] Development (show other bugs)
Hardware: x86 Linux
: High normal (vote)
Assignee: Gentoo Perl team
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2005-06-02 04:04 UTC by Phil Pennock
Modified: 2005-08-06 11:10 UTC (History)
0 users

See Also:
Package list:
Runtime testing required: ---


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Phil Pennock 2005-06-02 04:04:45 UTC
Running a stable x86 platform, with Perl and dev-perl/Term-ReadLine-Perl
installed, a process which uses Term::ReadLine will segfault on exit with an
error like:
*** glibc detected *** double free or corruption (!prev): 0x0829dc18 ***

Steps to Reproduce contains a very short perl script which demonstrates this
problem.

This broke on a glibc update a while back (I forget when, sorry).  I have
reinstalled both Perl and Term-ReadLine-Perl since then.  I have installed the
module after installing Perl.  ithreads is not enabled as a Perl use-flag.

Reproducible: Always
Steps to Reproduce:
#!/usr/bin/perl
# Run this script, provide some input when asked.
use strict;
use warnings;
use Term::ReadLine;

my $term = new Term::ReadLine "check_readline";
die "No terminal initialisation" unless defined $term;

my $foo = $term->readline('Enter your foo text here: ');
my $len = length $foo;
print "Input was $len chars long: {$foo}\n";

exit 0;

Actual Results:  
normal_prompt% ./check_readline 
Enter your foo text here: foo
Input was 3 chars long: {foo}
*** glibc detected *** double free or corruption (!prev): 0x08193c20 ***
zsh: abort (core dumped)  ./check_readline
{SIGABRT}-prompt% gdb /usr/bin/perl core.check_readline.30748
[...]
(gdb) bt
#0  0xffffe410 in __kernel_vsyscall ()
#1  0xb7e6bd21 in raise () from /lib/tls/libc.so.6
#2  0xb7e6d3e8 in abort () from /lib/tls/libc.so.6
#3  0xbfffea54 in ?? ()
[...]
#38 0xbfffeaf4 in ?? ()
#39 0xb7ea514b in free () from /lib/tls/libc.so.6
Previous frame inner to this frame (corrupt stack?)
(gdb)

Expected Results:  
Clean process exit, exit-status 0.  No glibc warnings.  No shell warnings of
signal death and core-dump.  No core-dump.

# qpkg -I dev-lang/perl -v
dev-lang/perl-5.8.5-r5 *
# qpkg -I dev-perl/Term-ReadLine-Perl -v
dev-perl/Term-ReadLine-Perl-1.0203 *
# emerge -pv dev-lang/perl dev-perl/Term-ReadLine-Perl
[...]
[ebuild   R   ] dev-lang/perl-5.8.5-r5  +berkdb -debug +doc +gdbm -ithreads
-perlsuid 0 kB 
[ebuild   R   ] dev-perl/Term-ReadLine-Perl-1.0203  0 kB 


Portage 2.0.51.19 (default-linux/x86/2005.0, gcc-3.3.5-20050130,
glibc-2.3.4.20041102-r1, 2.6.11-gentoo-r6 i686)
=================================================================
System uname: 2.6.11-gentoo-r6 i686 Intel(R) Pentium(R) 4 CPU 2.80GHz
Gentoo Base System version 1.4.16
Python:              dev-lang/python-2.3.5 [2.3.5 (#1, May  4 2005, 10:25:59)]
ccache version 2.3 [enabled]
dev-lang/python:     2.3.5
sys-apps/sandbox:    [Not Present]
sys-devel/autoconf:  2.59-r6, 2.13
sys-devel/automake:  1.7.9-r1, 1.8.5-r3, 1.5, 1.4_p6, 1.6.3, 1.9.5
sys-devel/binutils:  2.15.92.0.2-r7
sys-devel/libtool:   1.5.16
virtual/os-headers:  2.6.8.1-r2
ACCEPT_KEYWORDS="x86"
AUTOCLEAN="yes"
CFLAGS="-O2 -mcpu=pentium4 -march=pentium4 -mmmx -msse -msse2 -mfpmath=sse,387
-pipe"
CHOST="i686-pc-linux-gnu"
CONFIG_PROTECT="/etc /usr/kde/2/share/config /usr/kde/3/share/config
/usr/lib/X11/xkb /usr/lib/mozilla/defaults/pref /usr/share/config
/usr/share/texmf/dvipdfm/config/ /usr/share/texmf/dvips/config/
/usr/share/texmf/tex/generic/config/ /usr/share/texmf/tex/platex/config/
/usr/share/texmf/xdvi/ /var/qmail/control"
CONFIG_PROTECT_MASK="/etc/gconf /etc/terminfo /etc/env.d"
CXXFLAGS="-O2 -mcpu=pentium4 -march=pentium4 -mmmx -msse -msse2 -mfpmath=sse,387
-pipe"
DISTDIR="/usr/portage/distfiles"
FEATURES="autoaddcvs autoconfig ccache distlocks nostrip sandbox sfperms strict"
GENTOO_MIRRORS="http://ftp.easynet.nl/mirror/gentoo/
http://ftp.snt.utwente.nl/pub/os/linux/gentoo
http://ftp-stud.fht-esslingen.de/pub/Mirrors/gentoo/
http://pandemonium.tiscali.de/pub/gentoo/ http://ftp.du.se/pub/os/gentoo"
MAKEOPTS="-j2"
PKGDIR="/usr/portage/packages"
PORTAGE_TMPDIR="/var/tmp"
PORTDIR="/usr/portage"
SYNC="rsync://rsync4.nl.gentoo.org/gentoo-portage"
USE="x86 X acl acpi adns alsa apache2 apm avi berkdb bitmap-fonts bzlib caps cdb
cdr cjk crypt cscope cups curl curlwrappers doc dvd eds emboss encode evo fam
flac foomaticdb fortran gd gdbm ggi gif gmp gnome gnutls gpm gstreamer gtk gtk2
hardenedphp iconv imagemagick imap imlib imlib2 ipv6 java jpeg kerberos lcms
ldap libg++ libwww lzo mad maildir matrox mbox mcal memlimit mhash mikmod mime
mmx mng motif mozilla mp3 mpeg mysql ncurses netcdf nptl odbc offensive ogg
oggvorbis opengl pam pcre pdflib perl pic plotutils png postgres ppds python
quicktime readline real recode ruby samba sasl sdl silc slang sndfile snmp
sockets speex spell sse sse2 ssl svg tcpd tetex theora tiff truetype
truetype-fonts type1-fonts unicode usb vhosts vorbis win32codecs wmf xanim xine
xml xml2 xmms xprint xv xvid zlib userland_GNU kernel_linux elibc_glibc"
Unset:  ASFLAGS, CBUILD, CTARGET, LANG, LC_ALL, LDFLAGS, LINGUAS, PORTDIR_OVERLAY
Comment 1 Michael Cummings (RETIRED) gentoo-dev 2005-06-02 07:43:55 UTC
Doesn't dup over here 
  
Enter your foo text here: ahlo  
Input was 4 chars long: {ahlo}  
mcummings@randombox $  
  
Like you said - this looks like a problem between you and glibc, not the perl  
module. (glibc-2.3.4.20040808-r1, tried it on 3 boxes, fwiw)  
Comment 2 Ryan Hill (RETIRED) gentoo-dev 2005-06-02 22:15:28 UTC
use the nomalloccheck USE flag when emerging glibc to avoid these errors.
Comment 3 Phil Pennock 2005-06-05 09:05:31 UTC
(In reply to comment #1)
> Like you said - this looks like a problem between you and glibc, not the perl  
> module. (glibc-2.3.4.20040808-r1, tried it on 3 boxes, fwiw)  

The glibc check is a diagnostic to highlight a bug.  Unfortunately, I can't see
a way to turn it off without a re-emerge, as suggested by R.Hill; that's
underway now.  (FreeBSD's /etc/malloc.conf | $MALLOC_OPTIONS wins here.)

Unless there's a glibc bug in the free() checks, this means that there's a bug
either in the readline library or the Term::ReadLine perl module (and its XS
wrapping).  I have sys-devel/bc installed with the 'readline' USE-flag and
ldd(1) confirms that it links against libreadline; bc does not core-dump on
exit.  This suggests that the problem lies with Term::ReadLine itself.  Hence
the bug-report.

As a real-world example of an affected program: cpan(1)
Comment 4 Phil Pennock 2005-08-02 06:06:13 UTC
glibc no longer provides the nomalloccheck USE-flag on either x86 or ~x86.
As such, the complaints about double-free can no longer be avoided and any perl
script using Term::ReadLine is dying with SIGABRT on exit:

*** glibc detected *** double free or corruption (!prev): 0x083ac0d8 ***

sys-libs/glibc-2.3.5
  -build -debug -erandom -hardened (-multilib) -nls +nptl -nptlonly +pic
(-selinux) +userlocales
dev-lang/perl-5.8.6-r5
  +berkdb -build -debug +doc +gdbm -ithreads -minimal -perlsuid
dev-perl/Term-ReadLine-Perl-1.0203

If using the current Gentoo glibc on x86, can anyone else duplicate this?

Thanks,
Comment 5 Michael Cummings (RETIRED) gentoo-dev 2005-08-03 17:07:55 UTC
sys-libs/glibc-2.3.5

no sign of this bug.
Enter your foo text here: hi me
Input was 5 chars long: {hi me}
mcummings@nomad%
Comment 6 Phil Pennock 2005-08-06 11:10:41 UTC
Sorry, bug report is in error.

I hadn't remembered that when I'd installed Gentoo, I'd used Term::ReadLine::Gnu
which isn't in Portage, because I wanted the advanced features available from
the libreadline implementation.  I'd forgotten that although "use
Term::ReadLine" will use the ...::Gnu version if it's available, it's not
included by default.

The port is fine.  I had failed to rebuild Term::ReadLine::Gnu after an update
of Perl, because I'd forgotten that I'd installed some stuff before I learnt
about g-cpan.pl; I've now used g-cpan.pl so that this mistake should not be
repeated.

I'm sorry to have wasted peoples' time.  Thank you for being so patient with me
whilst I was a complete twit.