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
[PATCH] Segfault when calling ->next::method on non-existing package #9232
Comments
From ilmari@vesla.ilmari.orgThis is a bug report for perl from ilmari@ilmari.org, When calling ->next::can on a package name that hasn't been defined at Here's a patch with a test. I'm not entirely sure whether it should die mro.c | 5 ++++- Inline Patchdiff --git a/mro.c b/mro.c
index 83872dc..be9a5d4 100644
--- a/mro.c
+++ b/mro.c
@@ -953,8 +953,11 @@ XS(XS_mro_nextcan)
if(sv_isobject(self))
selfstash = SvSTASH(SvRV(self));
- else
+ else {
selfstash = gv_stashsv(self, 0);
+ if(!selfstash)
+ Perl_croak(aTHX_ "Can't call next::method/next::can/maybe::next::method on undefined package \"%s\".", SvPV_nolen_const(self));
+ }
assert(selfstash);
diff --git a/t/mro/next_edgecases.t b/t/mro/next_edgecases.t
index 91c2c85..9b872b6 100644
--- a/t/mro/next_edgecases.t
+++ b/t/mro/next_edgecases.t
@@ -3,7 +3,7 @@
use strict;
use warnings;
-require q(./test.pl); plan(tests => 11);
+require q(./test.pl); plan(tests => 12);
{
@@ -79,4 +79,16 @@ require q(./test.pl); plan(tests => 11);
eval { $baz->bar() };
ok($@, '... calling bar() with next::method failed') || diag $@;
}
+
+ # Test it failing (instead of segfaulting) with non-existing class
+ {
+ package Qux;
+ use mro;
+ sub foo { No::Such::Class->next::can }
+ }
+
+ eval { Qux->foo() };
+ like($@, qr{Can't call next::method/next::can/maybe::next::method on undefined package},
+ "->next::can on non-existing package name dies correctly")
+
}
--
Flags: Site configuration information for perl 5.11.0: Configured by ilmari at Sat Jan 26 04:38:10 GMT 2008. Summary of my perl5 (revision 5 version 11 subversion 0 patch 33054) configuration: Locally applied patches: @INC for perl 5.11.0: Environment for perl 5.11.0: |
From @rgsOn 22/02/2008, via RT ilmari @ vesla. ilmari. org
Thanks for this patch. Another alternative would be probably to Besides this, I don't like the wording of the error message, because
|
The RT System itself - Status changed from 'new' to 'open' |
@rgs - Status changed from 'open' to 'resolved' |
From @rgsOn 25/02/2008, Rafael Garcia-Suarez <rgarciasuarez@gmail.com> wrote:
That's what I applied : Change 33367 by rgs@stcosmo on 2008/02/25 10:54:47 Avoid a segfault case in MRO code, based on : Affected files ... ... //depot/perl/mro.c#46 edit Differences ... ==== //depot/perl/mro.c#46 (text) ==== @@ -954,7 +954,7 @@ assert(selfstash); ==== //depot/perl/t/mro/next_edgecases.t#2 (text) ==== @@ -3,7 +3,7 @@ -require q(./test.pl); plan(tests => 11); { @@ -78,5 +78,16 @@ eval { $baz->bar() }; |
From david@landgren.netRafael Garcia-Suarez wrote:
Minor quibble (I'm way behind on sumamrising)
I thought the general movement these days was to embed the bug number in
so is($@, '', "->next::can on non-existing package name (RT bug #51092)"); David |
From @nwc10On Wed, Feb 27, 2008 at 02:49:22PM +0100, David Landgren wrote:
Is there anything we can do to help this? Nicholas Clark |
From david@landgren.netNicholas Clark wrote:
I wasn't complaining, and in fact managed to finish the summary tonight.
Yes, that would be a good idea. Starting from now, you all have an David |
From @nwc10On Fri, Feb 29, 2008 at 12:41:24AM +0100, David Landgren wrote:
I asked Robert, and he said # ezmlm-list /home/perlmail/perl5-porters{,/digest} | wc -l Current stats seem to show about 38 messages per day. Sooooo If we all send two messages a week, that's 970 in total :-) Nicholas Clark |
Migrated from rt.perl.org#51092 (status was 'resolved')
Searchable as RT51092$
The text was updated successfully, but these errors were encountered: