develooper Front page | perl.perl5.porters | Postings from February 2008

[perl #51072] Method dispatch breaks with defined(\&sub)

Thread Next
From:
nagler @ bivio . biz
Date:
February 21, 2008 08:08
Subject:
[perl #51072] Method dispatch breaks with defined(\&sub)
Message ID:
rt-3.6.HEAD-29454-1203609388-1585.51072-75-0@perl.org
# New Ticket Created by  nagler@bivio.biz 
# Please include the string:  [perl #51072]
# in the subject line of all future correspondence about this issue. 
# <URL: http://rt.perl.org/rt3/Ticket/Display.html?id=51072 >



This is a bug report for perl from nagler@bivio.biz,
generated with the help of perlbug 1.35 running under perl v5.8.5.


-----------------------------------------------------------------
[Please enter your report here]
From: Rob Nagler <nagler@bivio.biz>
To: boulder-pm@pm.org
Subject: Re: [Boulder.pm] mod_perl package lexicals becoming corrupt
Date: Wed, 20 Feb 2008 12:49:32 -0700

Found the bug.  Here's what demonstrates it:

    package T1;
    use strict;
    sub s1 {}

    package T2;
    use base 'T1';
    use strict;

    package main;
    T2->s1;
    print("ok\n");
    \&T2::s1;
    print("not reached\n");
    T2->s1;

The \&T2:s1 autovivifies something in the package hash, which is
"nasty", and actually ends up corrupting the package hash so that
lexicals disappear.  We had a function called super_for_method, which
did this:

    foreach my $a (@{$proto->inheritance_ancestors}) {
 	my($sub) = \&{$a . '::' . $method};
 	next unless defined(&$sub);
 	return ($sub, $a);
    }

The fact that \&{} seems to autovivify an invalid package hash entry
is the problem.  You can implement the above this way:

    foreach my $a (@{$proto->inheritance_ancestors}) {
	my($sub) = $a . '::' . $method;
	do {
	    no strict 'refs';
	    next unless defined(&$sub);
	};
	return (\&$sub, $a);
    }

The above code does not corrupt the the package hash.  Both pieces of
code autovivify the glob for $sub, but in the former case, the
autovivification has a dangerous side effect of corrupting the entire
symbol table (in a subtle way, of course, which is why I got confused
by the number of lexicals).

Rob

[Please do not change anything below this line]
-----------------------------------------------------------------
---
Flags:
    category=core
    severity=medium
---
This perlbug was built using Perl v5.8.5 in the Red Hat build system.
It is being executed now by Perl v5.8.5 - Wed Nov  7 16:36:26 EST 2007.

Site configuration information for perl v5.8.5:

Configured by Red Hat, Inc. at Wed Nov  7 16:36:26 EST 2007.

Summary of my perl5 (revision 5 version 8 subversion 5) configuration:
  Platform:
    osname=linux, osvers=2.6.9-55.0.9.elsmp, archname=i386-linux-thread-multi
    uname='linux builder4.centos.org 2.6.9-55.0.9.elsmp #1 smp thu sep 27 18:27:41 edt 2007 i686 i686 i386 gnulinux '
    config_args='-des -Doptimize=-O2 -g -pipe -m32 -march=i386 -mtune=pentium4 -Dversion=5.8.5 -Dmyhostname=localhost -Dperladmin=root@localhost -Dcc=gcc -Dcf_by=Red Hat, Inc. -Dinstallprefix=/usr -Dprefix=/usr -Darchname=i386-linux -Dvendorprefix=/usr -Dsiteprefix=/usr -Duseshrplib -Dusethreads -Duseithreads -Duselargefiles -Dd_dosuid -Dd_semctl_semun -Di_db -Ui_ndbm -Di_gdbm -Di_shadow -Di_syslog -Dman3ext=3pm -Duseperlio -Dinstallusrbinperl -Ubincompat5005 -Uversiononly -Dpager=/usr/bin/less -isr -Dinc_version_list=5.8.4 5.8.3 5.8.2 5.8.1 5.8.0'
    hint=recommended, useposix=true, d_sigaction=define
    usethreads=define use5005threads=undef useithreads=define usemultiplicity=define
    useperlio=define d_sfio=undef uselargefiles=define usesocks=undef
    use64bitint=undef use64bitall=undef uselongdouble=undef
    usemymalloc=n, bincompat5005=undef
  Compiler:
    cc='gcc', ccflags ='-D_REENTRANT -D_GNU_SOURCE -DDEBUGGING -fno-strict-aliasing -pipe -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -I/usr/include/gdbm',
    optimize='-O2 -g -pipe -m32 -march=i386 -mtune=pentium4',
    cppflags='-D_REENTRANT -D_GNU_SOURCE -DDEBUGGING -fno-strict-aliasing -pipe -I/usr/local/include -I/usr/include/gdbm'
    ccversion='', gccversion='3.4.6 20060404 (Red Hat 3.4.6-8)', gccosandvers=''
    intsize=4, longsize=4, ptrsize=4, doublesize=8, byteorder=1234
    d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=12
    ivtype='long', ivsize=4, nvtype='double', nvsize=8, Off_t='off_t', lseeksize=8
    alignbytes=4, prototype=define
  Linker and Libraries:
    ld='gcc', ldflags =' -L/usr/local/lib'
    libpth=/usr/local/lib /lib /usr/lib
    libs=-lresolv -lnsl -lgdbm -ldb -ldl -lm -lcrypt -lutil -lpthread -lc
    perllibs=-lresolv -lnsl -ldl -lm -lcrypt -lutil -lpthread -lc
    libc=/lib/libc-2.3.4.so, so=so, useshrplib=true, libperl=libperl.so
    gnulibc_version='2.3.4'
  Dynamic Linking:
    dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags='-Wl,-E -Wl,-rpath,/usr/lib/perl5/5.8.5/i386-linux-thread-multi/CORE'
    cccdlflags='-fPIC', lddlflags='-shared -L/usr/local/lib'

Locally applied patches:
    

---
@INC for perl v5.8.5:
    /home/nagler/src/perl
    /usr/lib/perl5/5.8.5/i386-linux-thread-multi
    /usr/lib/perl5/5.8.5
    /usr/lib/perl5/site_perl/5.8.5/i386-linux-thread-multi
    /usr/lib/perl5/site_perl/5.8.4/i386-linux-thread-multi
    /usr/lib/perl5/site_perl/5.8.3/i386-linux-thread-multi
    /usr/lib/perl5/site_perl/5.8.2/i386-linux-thread-multi
    /usr/lib/perl5/site_perl/5.8.1/i386-linux-thread-multi
    /usr/lib/perl5/site_perl/5.8.0/i386-linux-thread-multi
    /usr/lib/perl5/site_perl/5.8.5
    /usr/lib/perl5/site_perl/5.8.4
    /usr/lib/perl5/site_perl/5.8.3
    /usr/lib/perl5/site_perl/5.8.2
    /usr/lib/perl5/site_perl/5.8.1
    /usr/lib/perl5/site_perl/5.8.0
    /usr/lib/perl5/site_perl
    /usr/lib/perl5/vendor_perl/5.8.5/i386-linux-thread-multi
    /usr/lib/perl5/vendor_perl/5.8.4/i386-linux-thread-multi
    /usr/lib/perl5/vendor_perl/5.8.3/i386-linux-thread-multi
    /usr/lib/perl5/vendor_perl/5.8.2/i386-linux-thread-multi
    /usr/lib/perl5/vendor_perl/5.8.1/i386-linux-thread-multi
    /usr/lib/perl5/vendor_perl/5.8.0/i386-linux-thread-multi
    /usr/lib/perl5/vendor_perl/5.8.5
    /usr/lib/perl5/vendor_perl/5.8.4
    /usr/lib/perl5/vendor_perl/5.8.3
    /usr/lib/perl5/vendor_perl/5.8.2
    /usr/lib/perl5/vendor_perl/5.8.1
    /usr/lib/perl5/vendor_perl/5.8.0
    /usr/lib/perl5/vendor_perl
    .

---
Environment for perl v5.8.5:
    HOME=/home/nagler
    LANG=en_US.UTF-8
    LANGUAGE (unset)
    LD_LIBRARY_PATH (unset)
    LOGDIR (unset)
    PATH=/usr/java/jdk1.5.0_14/bin:/home/nagler/bin:/usr/kerberos/bin:/usr/local/bin:/bin:/usr/bin:/usr/X11R6/bin:/usr/local/oracle/product/8.1.6/bin:/home/nagler/bin
    PERLLIB=/home/nagler/src/perl
    PERL_BADLANG (unset)
    PERL_MM_OPT=PREFIX=/home/nagler INSTALLMAN1DIR=/home/nagler/man/man1 INSTALLMAN3DIR=/home/nagler/man/man3
    SHELL=/bin/bash


Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About