Undefined lex sub used as inherited method crashes
authorFather Chrysostomos <sprout@cpan.org>
Sat, 2 Nov 2013 13:17:23 +0000 (06:17 -0700)
committerFather Chrysostomos <sprout@cpan.org>
Sat, 2 Nov 2013 13:17:23 +0000 (06:17 -0700)
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
t/op/lexsub.t

diff --git a/gv.c b/gv.c
index e7ef9a7..2b88129 100644 (file)
--- 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);
index d717f42..0be305b 100644 (file)
@@ -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;
+}