Perl / perl5

🐪 The Perl programming language
https://dev.perl.org/perl5/
Other
1.93k stars 552 forks source link

Core dump in 5.6.0 #2225

Closed p5pRT closed 20 years ago

p5pRT commented 24 years ago

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

Searchable as RT3536$

p5pRT commented 24 years ago

From jcarey@us.oracle.com

Created by jcarey@us.oracle.com

The following script causes a Bus error in 5.6.0; it fails silently in 5.004_05

----

use File​::Find; sub wanted {   next unless /i/; #should be return

}

find (\&wanted\, '.') ---

Dbx reports the following backtrace​:

=>[1] Perl_av_pop(0x3a3a7761\, 0x0\, 0x2\, 0x11ca68\, 0x7\, 0x111b38)\, at 0x7def4   [2] Perl_pp_pop(0x118800\, 0x118400\, 0x11c018\, 0x3a3a7761\, 0x11c014\, 0x3a3a7761)\, at 0xa56e4   [3] Perl_runops_standard(0x1187e0\, 0xffbe6b74\, 0xff2338f0\, 0x0\, 0xffbe6dd8\, 0x0)\, at 0x7f7b0   [4] S_run_body(0x1\, 0x118400\, 0x113400\, 0x118000\, 0x0\, 0x119870)\, at 0x2abb0   [5] perl_run(0x119004\, 0x27734\, 0x2\, 0xffbe6c94\, 0x0\, 0x2)\, at 0x2a8a0   [6] main(0x0\, 0x117b80\, 0xffbe6c94\, 0x10c000\, 0x0\, 0x0)\, at 0x276f4

Perl Info ``` Flags: category=core severity=high Site configuration information for perl v5.6.0: Configured by jcarey at Mon Jul 17 10:31:00 EDT 2000. Summary of my perl5 (revision 5.0 version 6 subversion 0) configuration: Platform: osname=solaris, osvers=2.7, archname=sun4-solaris uname='sunos cykick 5.7 generic_106541-07 sun4u sparc sunw,ultra-5_10 ' config_args='-de' hint=recommended, useposix=true, d_sigaction=define usethreads=undef use5005threads=undef useithreads=undef usemultiplicity=undef useperlio=undef d_sfio=undef uselargefiles=define use64bitint=undef use64bitall=undef uselongdouble=undef usesocks=undef Compiler: cc='cc', optimize='-O', gccversion= cppflags='-I/usr/local/include' ccflags ='-I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64' stdchar='char', d_stdstdio=define, usevfork=false intsize=4, longsize=4, ptrsize=4, doublesize=8 d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=16 ivtype='long', ivsize=4, nvtype='double', nvsize=8, Off_t='off_t', lseeksize=8 alignbytes=8, usemymalloc=y, prototype=define Linker and Libraries: ld='cc', ldflags =' -L/usr/local/lib -L/opt/SUNWspro/SC5.0/lib ' libpth=/usr/local/lib /opt/SUNWspro/SC5.0/lib /lib /usr/lib /usr/ccs/lib libs=-lsocket -lnsl -ldl -lm -lc -lcrypt -lsec libc=/lib/libc.so, so=so, useshrplib=false, libperl=libperl.a Dynamic Linking: dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags=' ' cccdlflags='-KPIC', lddlflags='-G -L/usr/local/lib -L/opt/SUNWspro/SC5.0/lib' Locally applied patches: @INC for perl v5.6.0: /usr/local/lib/perl5/5.6.0/sun4-solaris /usr/local/lib/perl5/5.6.0 /usr/local/lib/perl5/site_perl/5.6.0/sun4-solaris /usr/local/lib/perl5/site_perl/5.6.0 /usr/local/lib/perl5/site_perl . Environment for perl v5.6.0: HOME=/export/home/jcarey LANG=C LANGUAGE (unset) LD_LIBRARY_PATH=/usr/openwin/lib:/usr/5lib:/usr/lib:/vobs/olap/oes/kits/dbg:/usr/dt/lib:/dat3/jcarey/oracle/oracle/rdbms/lib:/dat3/jcarey/oracle/oracle/lib:/dat3/jcarey/oracle/oracle/ctx/lib:/vobs/dbfs/lib:/vobs/dbfs/external/JWS1.2/lib/solaris/sparc:/dat3/jcarey/oracle/oracle/javavm/utl/ejb/unix/lib:/dat3/jcarey/dbjava/lib:/net/stvob9/stv9/oracle_815/lib:/usr/lib:/usr/ucblib:/usr/openwin/lib:/usr/dt/lib:/dat3/jcarey/oracle/oracle/lib:/dat3/jcarey/oracle/oracle/bin LOGDIR (unset) PATH=/usr/openwin/bin/xview:/home/bin:/usr/openwin/bin:/usr/openwin/bin/xview:/usr/openwin/demo:/usr/openwin/bin/xview:/home/bin:/usr/openwin/bin:/usr/openwin/bin/xview:/usr/openwin/demo:/opt/SUNWspro/SC5.0/bin:/opt/SUNWspro/bin:/usr/local/bin:/usr/5bin:/usr/local:/usr/ucb:/usr/bin:/usr/etc:.:/export/home/jcarey/bin:/usr/atria/bin:/usr/dt/bin:/dat3/jcarey/oracle/oracle/bin:/dat3/jcarey/oracle/utl:/usr/ccs/bin:/export/home/jcarey/olint/bin PERL_BADLANG (unset) SHELL=/bin/ksh ```
p5pRT commented 24 years ago

From [Unknown Contact. See original ticket]

Jim Carey (lists.p5p)​:

use File​::Find; sub wanted { next unless /i/; #should be return } find (\&wanted\, '.')

Fixed in perl-current; close that bug!

p5pRT commented 24 years ago

From [Unknown Contact. See original ticket]

simon@​brecon.co.uk (Simon Cozens) wrote

Fixed in perl-current; close that bug!

It's certainly changed in perl-current\, but I'm not sure it's entirely fixed.

Running his example under perl-current with -wd\, I see

  DB\<2> c 4 main​::wanted(-​:4)​: next unless /i/; #should be return   DB\<3> T . = main​::wanted called from file `lib/File/Find.pm' line 432 . = File​::Find​::_find_dir(ref(HASH)\, .\, 30) called from file `lib/File/Find.pm' line 342 . = File​::Find​::_find_opt(ref(HASH)\, .) called from file `lib/File/Find.pm' line 719 . = File​::Find​::find(ref(CODE)\, .) called from file `-' line 11   DB\<3> s Exiting subroutine via next at - line 4. Exiting subroutine via next at - line 4. File​::Find​::_find_dir(lib/File/Find.pm​:511)​: 511​: while ( defined ($SE = pop @​Stack) ) {   DB\<3> w 427 424
425​: while (defined $SE) { 426​: unless ($bydepth) { 427​: $dir= $p_dir; 428​: $name= $dir_name; 429​: $_= ($no_chdir ? $dir_name : $dir_rel ); 430 # prune may happen here 431​: $prune= 0; 432​: &$wanted_callback; 433​: next if $prune;   DB\<4>

[ Exercise for the reader - why does the error message happen twice? ]

So the subroutine being exited is being called from line 432. And the smallest surrounding loop to that is the while() on line 425. But the "next" in fact takes us to line 511. Hmmm...

And it also occurs to me that things like File​::Find doing callbacks should protect themselves against wild loop control statements. See the attached patch.

Perhaps Perl should *define* loop controls which exit subroutines as equivalent to "return;" ?

Mike Guy

Inline Patch ```diff --- ./lib/File/Find.pm.orig Tue Jul 11 22:19:19 2000 +++ ./lib/File/Find.pm Tue Jul 18 11:20:21 2000 @@ -373,7 +373,7 @@ $name = $abs_dir . $_; - &$wanted_callback; + { &$wanted_callback }; # protect against wild "next" } @@ -429,7 +429,7 @@ $_= ($no_chdir ? $dir_name : $dir_rel ); # prune may happen here $prune= 0; - &$wanted_callback; + { &$wanted_callback }; # protect against wild "next" next if $prune; } @@ -472,7 +472,7 @@ $name = $dir_pref . $FN; $_ = ($no_chdir ? $name : $FN); - &$wanted_callback; + { &$wanted_callback }; # protect against wild "next" } } @@ -496,13 +496,13 @@ else { $name = $dir_pref . $FN; $_= ($no_chdir ? $name : $FN); - &$wanted_callback; + { &$wanted_callback }; # protect against wild "next" } } else { $name = $dir_pref . $FN; $_= ($no_chdir ? $name : $FN); - &$wanted_callback; + { &$wanted_callback }; # protect against wild "next" } } } @@ -528,7 +528,7 @@ if ( substr($_,-2) eq '/.' ) { s|/\.$||; } - &$wanted_callback; + { &$wanted_callback }; # protect against wild "next" } else { push @Stack,[$CdLvl,$p_dir,$dir_rel,-1] if $bydepth; last; @@ -602,7 +602,7 @@ # prune may happen here $prune= 0; lstat($_); # make sure file tests with '_' work - &$wanted_callback; + { &$wanted_callback }; # protect against wild "next" next if $prune; } @@ -652,7 +652,7 @@ $fullname = $new_loc; $name = $dir_pref . $FN; $_ = ($no_chdir ? $name : $FN); - &$wanted_callback; + { &$wanted_callback }; # protect against wild "next" } } @@ -686,7 +686,7 @@ } lstat($_); # make sure file tests with '_' work - &$wanted_callback; + { &$wanted_callback }; # protect against wild "next" } else { push @Stack,[$dir_loc, $pdir_loc, $p_dir, $dir_rel,-1] if $bydepth; last; End of patch ```
p5pRT commented 24 years ago

From [Unknown Contact. See original ticket]

From​: "M.J.T. Guy" \mjtg@&#8203;cus\.cam\.ac\.uk

Perhaps Perl should *define* loop controls which exit subroutines as equivalent to "return;" ?

Why? What's wrong with just return?

p5pRT commented 24 years ago

From [Unknown Contact. See original ticket]

"Bryan C. Warnock" \bwarnock@&#8203;gtemail\.net wrote

From​: "M.J.T. Guy" \mjtg@&#8203;cus\.cam\.ac\.uk

Perhaps Perl should *define* loop controls which exit subroutines as equivalent to "return;" ?

Why? What's wrong with just return?

You're asking the question the wrong way round. People *shouldn't* use 'next' etc in this circumstance. But they may do\, and this can confuse the logic of callers\, such as File​::Find. The suggested change would obviate the need for precautionary coding such as in my patch.

And since it may not have been obvious\, the suggestion wasn't really serious. It'd never get past the Backward Compatibility Police.

But having to defend callbacks like that is a pain.

Mike Guy

p5pRT commented 24 years ago

From [Unknown Contact. See original ticket]

Perhaps Perl should *define* loop controls which exit subroutines as equivalent to "return;" ?

Why? What's wrong with just return?

You're asking the question the wrong way round. People *shouldn't* use 'next' etc in this circumstance. But they may do\, and this can confuse the logic of callers\, such as File​::Find. The suggested change would obviate the need for precautionary coding such as in my patch.

Sorry. Bad parsing.... :-) I was inserting an implicit "new" between define and loop.

p5pRT commented 24 years ago

From @jhi

On Tue\, Jul 18\, 2000 at 11​:30​:16AM +0100\, M.J.T. Guy wrote​:

And it also occurs to me that things like File​::Find doing callbacks should protect themselves against wild loop control statements. See the attached patch.

Which has been now applied.

Perhaps Perl should *define* loop controls which exit subroutines as equivalent to "return;" ?

A very good question (and something to define in more detail for Perl 6\, certainly).

p5pRT commented 24 years ago

From [Unknown Contact. See original ticket]

Jarkko Hietaniemi \jhi@&#8203;iki\.fi wrote

On Tue\, Jul 18\, 2000 at 11​:30​:16AM +0100\, M.J.T. Guy wrote​:

Perhaps Perl should *define* loop controls which exit subroutines as equivalent to "return;" ?

A very good question (and something to define in more detail for Perl 6\, certainly).

As I remarked in a followup message\, that wasn't intended entirely seriously\, for compatibility reasons.

And if it's to be changed in Perl 6\, the Right Thing would be to make it an error\, so that loop controls are defined lexically and can be entirely bound at compile time.

Mike Guy