From 8bfda0d7d50f05de298abca907611be9a33d1626 Mon Sep 17 00:00:00 2001 From: Father Chrysostomos Date: Sat, 2 Nov 2013 06:17:23 -0700 Subject: [PATCH] Undefined lex sub used as inherited method crashes MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Thanks to misuse of CvGV. $ perl5.19.5 -XMfeature=:all -e 'my sub foo {} undef &foo; *UNIVERSAL::bar = \&foo; main->bar()' Segmentation fault: 11 When deciding under which name to autoload the sub, we can’t assume CvGV(that_sub) is a GV, as it may be null. --- gv.c | 2 +- t/op/lexsub.t | 13 ++++++++++++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/gv.c b/gv.c index e7ef9a7..2b88129 100644 --- a/gv.c +++ b/gv.c @@ -1057,7 +1057,7 @@ Perl_gv_fetchmethod_pvn_flags(pTHX_ HV *stash, const char *name, const STRLEN le GV* stubgv; GV* autogv; - if (CvANON(cv)) + if (CvANON(cv) || !CvGV(cv)) stubgv = gv; else { stubgv = CvGV(cv); diff --git a/t/op/lexsub.t b/t/op/lexsub.t index d717f42..0be305b 100644 --- a/t/op/lexsub.t +++ b/t/op/lexsub.t @@ -8,7 +8,7 @@ BEGIN { *bar::like = *like; } no warnings 'deprecated'; -plan 138; +plan 139; # -------------------- Errors with feature disabled -------------------- # @@ -716,3 +716,14 @@ like runperl( ), qr/Constant subroutine foo undefined at /, 'constant undefinition warnings for lexical subs do not crash'; + +{ + my sub foo; + *AutoloadTestSuper::blah = \&foo; + sub AutoloadTestSuper::AUTOLOAD { + is $AutoloadTestSuper::AUTOLOAD, "AutoloadTestSuper::blah", + "Autoloading via inherited lex stub"; + } + @AutoloadTest::ISA = AutoloadTestSuper::; + AutoloadTest->blah; +} -- 2.7.4