From: Adriano Ferreira Date: Thu, 24 Aug 2006 10:20:43 +0000 (-0300) Subject: Re: [perl #40216] SelfLoader::croak doesn't protect $@ from being clobbered by require X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=cca8f13b7a786baee2df1fba298a1923907c3bad;p=p5sagit%2Fp5-mst-13.2.git Re: [perl #40216] SelfLoader::croak doesn't protect $@ from being clobbered by require From: "Adriano Ferreira" Message-ID: <73ddeb6c0608240620s207124d1mc202aea6a4598576@mail.gmail.com> p4raw-id: //depot/perl@28758 --- diff --git a/MANIFEST b/MANIFEST index d742541..247d50b 100644 --- a/MANIFEST +++ b/MANIFEST @@ -2384,6 +2384,7 @@ lib/SelectSaver.pm Enforce proper select scoping lib/SelectSaver.t See if SelectSaver works lib/SelfLoader.pm Load functions only on demand lib/SelfLoader.t See if SelfLoader works +lib/SelfLoader-buggy.t See if SelfLoader works lib/Shell.pm Make AUTOLOADed system() calls lib/Shell.t Tests for above lib/shellwords.pl Perl library to split into words with shell quoting diff --git a/lib/SelfLoader-buggy.t b/lib/SelfLoader-buggy.t new file mode 100644 index 0000000..e8eb19a --- /dev/null +++ b/lib/SelfLoader-buggy.t @@ -0,0 +1,50 @@ +#!./perl + +BEGIN { + if( $ENV{PERL_CORE} ) { + chdir 't' if -d 't'; + @INC = '../lib'; + } +} + +use SelfLoader; + +# this script checks that errors on self-loaded +# subroutines that affect $@ are reported + +eval { buggy(); }; +unless ($@ =~ /^syntax error/) { + print "not "; +} +print "ok 1 - syntax errors are reported\n"; + +__END__ + +sub buggy +{ + +>*; +} + + +=head1 RT 40216 + + by Bo Lindbergh , at Aug 22, 2006 5:42 PM + +In the example below, there's a syntax error in the selfloaded +code for main::buggy. When the eval fails, SelfLoader::AUTOLOAD +tries to report this with "croak $@;". Unfortunately, +SelfLoader::croak does "require Carp;" without protecting $@, +which gets clobbered. The program then dies with the +uninformative message " at ./example line 3". + +#! /usr/local/bin/perl +use SelfLoader; +buggy(); +__END__ +sub buggy +{ + +>*; +} + +=cut + diff --git a/lib/SelfLoader.pm b/lib/SelfLoader.pm index 87587c3..294b6bc 100644 --- a/lib/SelfLoader.pm +++ b/lib/SelfLoader.pm @@ -16,8 +16,10 @@ $nested = qr{ \( (?: (?> [^()]+ ) | (??{ $nested }) )* \) }x; our $one_attr = qr{ (?> (?! \d) \w+ (?:$nested)? ) (?:\s*\:\s*|\s+(?!\:)) }x; our $attr_list = qr{ \s* : \s* (?: $one_attr )* }x; -sub croak { require Carp; goto &Carp::croak } -sub carp { require Carp; goto &Carp::carp } +# in croak and carp, protect $@ from "require Carp;" RT #40216 + +sub croak { { local $@; require Carp; } goto &Carp::croak } +sub carp { { local $@; require Carp; } goto &Carp::carp } AUTOLOAD { print STDERR "SelfLoader::AUTOLOAD for $AUTOLOAD\n" if $DEBUG;