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

Problem with autouse (causing Perl to crash) #7307

Closed
p5pRT opened this issue May 19, 2004 · 5 comments
Closed

Problem with autouse (causing Perl to crash) #7307

p5pRT opened this issue May 19, 2004 · 5 comments

Comments

@p5pRT
Copy link

p5pRT commented May 19, 2004

Migrated from rt.perl.org#29708 (status was 'resolved')

Searchable as RT29708$

@p5pRT
Copy link
Author

p5pRT commented May 19, 2004

From @steve-m-hay

Created by @steve-m-hay

I have a problem using the "autouse" pragma which is causing perl
(5.8.4) to crash. I've reduced it to the following two modules​:

Foo.pm

package Foo;
use Exporter qw();
our @​EXPORT = qw(foo);
our @​ISA = qw(Exporter);
sub foo() { require Bar; Bar​::bar() }
1;

Bar.pm

package Bar;
use autouse 'Foo' => qw(foo());
my $done = 0;
sub bar() {
  return if $done;
  $done = 1;
  print "calling foo() once ...\n";
  foo();
  print "... ok\n";
  print "calling foo() again ...\n";
  foo();
  print "... ok\n";
}
1;

Running​:

  >perl -MBar -MFoo -we "Foo​::foo()"

produces the output​:

  calling foo() once ...
  ... ok
  calling foo() again ...

and then perl.exe crashes with an Access Violation. Here's a stacktrace
from the crash (under perl-5.8.4)​:

Perl_pp_entersub() line 2912 + 2 bytes
Perl_runops_standard() line 24 + 3 bytes
S_run_body(long 1) line 1924
perl_run(interpreter * 0x00223c40) line 1840 + 9 bytes
RunPerl(int 5, char * * 0x00223c00, char * * 0x00222ba8) line 202 + 6 bytes
PERL! mainCRTStartup + 227 bytes
KERNEL32! 77e814c7()

The same command-line runs fine, producing the second "... ok" line,
under the "-d" debugger (e.g. perl -d​:ptkdb -MBar -MFoo -we "Foo​::foo()").

I can fix it by reversing the order in which the Foo and Bar modules are
loaded​:

  >perl -MFoo -MBar -we "Foo​::foo()"

or by not loading Bar initially​:

  >perl -MFoo -we "Foo​::foo()"

or by changing the following line within Bar.pm​:

  use autouse 'Foo' => qw(foo());

to either​:

  use autouse 'Foo' => qw(foo);

(!!!) or simply​:

  use Foo;

(understandable).

Perl Info

Flags:
    category=core
    severity=medium

Site configuration information for perl v5.8.4:

Configured by steveh at Mon Apr 26 14:01:56 2004.

Summary of my perl5 (revision 5 version 8 subversion 4) configuration:
  Platform:
    osname=MSWin32, osvers=4.0, archname=MSWin32-x86-perlio
    uname=''
    config_args='undef'
    hint=recommended, useposix=true, d_sigaction=undef
    usethreads=undef use5005threads=undef useithreads=undef 
usemultiplicity=undef
    useperlio=define d_sfio=undef uselargefiles=undef usesocks=undef
    use64bitint=undef use64bitall=undef uselongdouble=undef
    usemymalloc=y, bincompat5005=undef
  Compiler:
    cc='cl', ccflags ='-nologo -Gf -W3 -MD -Zi -DNDEBUG -O1 -DWIN32 
-D_CONSOLE -DNO_STRICT -DHAVE_DES_FCRYPT  -DPERL_DEBUGGING_MSTATS 
-DUSE_PERLIO -DPERL_MSVCRT_READFIX',
    optimize='-MD -Zi -DNDEBUG -O1',
    cppflags='-DWIN32'
    ccversion='', gccversion='', gccosandvers=''
    intsize=4, longsize=4, ptrsize=4, doublesize=8, byteorder=1234
    d_longlong=undef, longlongsize=8, d_longdbl=define, longdblsize=10
    ivtype='long', ivsize=4, nvtype='double', nvsize=8, Off_t='off_t', 
lseeksize=4
    alignbytes=8, prototype=define
  Linker and Libraries:
    ld='link', ldflags ='-nologo -nodefaultlib -debug -opt:ref,icf  
-libpath:"C:\perl5\lib\CORE"  -machine:x86'
    libpth=C:\PROGRA~1\MICROS~2\VC98\lib
    libs=  oldnames.lib kernel32.lib user32.lib gdi32.lib winspool.lib  
comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib  
netapi32.lib uuid.lib wsock32.lib mpr.lib winmm.lib  version.lib 
odbc32.lib odbccp32.lib msvcrt.lib
    perllibs=  oldnames.lib kernel32.lib user32.lib gdi32.lib 
winspool.lib  comdlg32.lib advapi32.lib shell32.lib ole32.lib 
oleaut32.lib  netapi32.lib uuid.lib wsock32.lib mpr.lib winmm.lib  
version.lib odbc32.lib odbccp32.lib msvcrt.lib
    libc=msvcrt.lib, so=dll, useshrplib=yes, libperl=perl58.lib
    gnulibc_version='undef'
  Dynamic Linking:
    dlsrc=dl_win32.xs, dlext=dll, d_dlsymun=undef, ccdlflags=' '
    cccdlflags=' ', lddlflags='-dll -nologo -nodefaultlib -debug 
-opt:ref,icf  -libpath:"C:\perl5\lib\CORE"  -machine:x86'

Locally applied patches:
    


@INC for perl v5.8.4:
    C:/perl5/lib
    C:/perl5/site/lib
    .


Environment for perl v5.8.4:
    HOME (unset)
    LANG (unset)
    LANGUAGE (unset)
    LD_LIBRARY_PATH (unset)
    LOGDIR (unset)
    
PATH=C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\perl5\bin
    PERL_BADLANG (unset)
    SHELL (unset)




------------------------------------------------
Radan Computational Ltd.

The information contained in this message and any files transmitted with it are confidential and intended for the addressee(s) only.  If you have received this message in error or there are any problems, please notify the sender immediately.  The unauthorized use, disclosure, copying or alteration of this message is strictly forbidden.  Note that any views or opinions presented in this email are solely those of the author and do not necessarily represent those of Radan Computational Ltd.  The recipient(s) of this message should check it and any attached files for viruses: Radan Computational will accept no liability for any damage caused by any virus transmitted by this email.


@p5pRT
Copy link
Author

p5pRT commented May 29, 2004

From @nwc10

On Wed, May 19, 2004 at 11​:00​:58AM -0000, Steve Hay wrote​:

I have a problem using the "autouse" pragma which is causing perl
(5.8.4) to crash. I've reduced it to the following two modules​:

$ valgrind --db-attach=yes ./perl -Ilib -MBar -MFoo -we "Foo​::foo()"
==25808== Memcheck, a memory error detector for x86-linux.
==25808== Copyright (C) 2002-2004, and GNU GPL'd, by Julian Seward.
==25808== Using valgrind-2.1.1, a program supervision framework for x86-linux.
==25808== Copyright (C) 2000-2004, and GNU GPL'd, by Julian Seward.
==25808== For more details, rerun with​: -v
==25808==
==25808== Syscall param sigaction(act) contains uninitialised or unaddressable byte(s)
==25808== at 0x3C0F9025​: __libc_sigaction (in /lib/tls/libc-2.3.2.so)
==25808== by 0x7F​: ???
==25808== Address 0x4FFFE980 is on thread 1's stack
==25808==
==25808== ---- Attach to debugger ? --- [Return/N/n/Y/y/C/c] ---- n
calling foo() once ...
... ok
calling foo() again ...
==25808==
==25808== Invalid read of size 1
==25808== at 0x80F3148​: Perl_pp_entersub (pp_hot.c​:2701)
==25808== by 0x80CBDF2​: Perl_runops_debug (dump.c​:1564)
==25808== by 0x80668DF​: S_run_body (perl.c​:1796)
==25808== by 0x8066308​: perl_run (perl.c​:1714)
==25808== Address 0x2C is not stack'd, malloc'd or free'd
==25808==
==25808== ---- Attach to debugger ? --- [Return/N/n/Y/y/C/c] ---- y

...

0x080f3148 in Perl_pp_entersub (my_perl=0x3c20d024) at pp_hot.c​:2701
2701 if (AvREAL(av)) {
(gdb) print av
$1 = (AV *) 0x3c20d6c0
(gdb) print *av
$2 = {sv_any = 0x0, sv_refcnt = 2147483529, sv_flags = 8388608}
(gdb) where
#0 0x080f3148 in Perl_pp_entersub (my_perl=0x3c20d024) at pp_hot.c​:2701
#1 0x080cbdf3 in Perl_runops_debug (my_perl=0x3c20d024) at dump.c​:1564
#2 0x080668e0 in S_run_body (my_perl=0x3c20d024, oldscope=1) at perl.c​:1796
#3 0x08066309 in perl_run (my_perl=0x3c20d024) at perl.c​:1714
#4 0x0805fdc8 in main (argc=6, argv=0x4fffec24, env=0x4fffec40)
  at perlmain.c​:86

2147483529 is 0x7fffff89

I'm not sure where to go next. That first sigaction warning is irritating,
but I don't think that it's relevant.

Nicholas Clark

@p5pRT
Copy link
Author

p5pRT commented May 29, 2004

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

@p5pRT
Copy link
Author

p5pRT commented May 30, 2004

From @iabyn

On Sat, May 29, 2004 at 09​:00​:25PM +0100, Nicholas Clark wrote​:

On Wed, May 19, 2004 at 11​:00​:58AM -0000, Steve Hay wrote​:

I have a problem using the "autouse" pragma which is causing perl
(5.8.4) to crash. I've reduced it to the following two modules​:

it can be reduced to the following​:

  $done = 0;
  sub f {
  return if $done;
  $done = 1;
  my $anon = sub { goto &f };
  &$anon;
  f();
  }

  f();

basically the first time f() is called at nested depth 2, its via goto &f,
and asince the caller of the goto was invoked without args (&$anon), an
@​_ array wasn't created at slot 0 in the depth-2 pad.
The next time f() was called convetionally deth 2, there was already
a pad for this depth, but slot 0 contained &PL_sv_undef rather than an AV.

I've fixed it so that goto &f unconditionally creates a new @​_ in slot 0.

Dave.

--
The Enterprise successfully ferries an alien VIP from one place to another
without serious incident.
  -- Things That Never Happen in "Star Trek" #7

Change 22870 by davem@​davem-percy on 2004/05/30 14​:30​:45

  [perl #29708] Problem with autouse (causing Perl to crash)
  @​_ sometimes wasn't getting created right

Affected files ...

... //depot/perl/pad.c#32 edit
... //depot/perl/pp_ctl.c#394 edit
... //depot/perl/t/op/goto.t#22 edit

Differences ...

==== //depot/perl/pad.c#32 (text) ====

@​@​ -1523,6 +1523,9 @​@​
=cut
*/

+/* XXX pad_push is now always called with has_args == 1. Get rid of
+ * this arg at some point */
+
void
Perl_pad_push(pTHX_ PADLIST *padlist, int depth, int has_args)
{

==== //depot/perl/pp_ctl.c#394 (text) ====

@​@​ -2329,7 +2329,7 @​@​
  else {
  if (CvDEPTH(cv) == 100 && ckWARN(WARN_RECURSION))
  sub_crush_depth(cv);
- pad_push(padlist, CvDEPTH(cv), cx->blk_sub.hasargs);
+ pad_push(padlist, CvDEPTH(cv), 1);
  }
  PAD_SET_CUR(padlist, CvDEPTH(cv));
  if (cx->blk_sub.hasargs)

==== //depot/perl/t/op/goto.t#22 (xtext) ====

@​@​ -7,7 +7,7 @​@​
  @​INC = qw(. ../lib);
}

-print "1..32\n";
+print "1..33\n";

require "test.pl";

@​@​ -229,6 +229,19 @​@​
print "not ";
returned_label : print "ok 32 - done to returned_label\n";

+# [perl #29708] - goto &foo could leave foo() at depth two with
+# @​_ == PL_sv_undef, causing a coredump
+
+
+my $r = runperl(
+ prog =>
+ 'sub f { return if $d; $d=1; my $a=sub {goto &f}; &$a; f() } f(); print qq(ok\n)',
+ stderr => 1
+ );
+print "not " if $r ne "ok\n";
+print "ok 33 - avoid pad without an \@​_\n";
+
+
exit;

bypass​:

@p5pRT
Copy link
Author

p5pRT commented May 30, 2004

@iabyn - Status changed from 'open' to 'resolved'

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

1 participant