[perl #102586] version->new("version") SEGVs
authorFather Chrysostomos <sprout@cpan.org>
Wed, 23 Nov 2011 05:28:15 +0000 (21:28 -0800)
committerFather Chrysostomos <sprout@cpan.org>
Wed, 23 Nov 2011 05:29:35 +0000 (21:29 -0800)
This adds an ROK check after calling sv_derived_from, as the latter
also works for class names.  It is done after sv_derived_from, rather
than before, as sv_derived_from calls get-magic.

ext/arybase/arybase.pm
lib/version.t
util.c

index 829f2db..aa3946d 100644 (file)
@@ -1,6 +1,6 @@
 package arybase;
 
-our $VERSION = "0.01";
+our $VERSION = "0.02";
 
 require XSLoader;
 XSLoader::load(); # This returns true, which makes require happy.
index dd47e87..da11023 100644 (file)
@@ -739,6 +739,19 @@ SKIP: {
     }
 }
 
+eval { version->new("version") };
+pass('no crash with version->new("version")');
+{
+    package _102586;
+    sub TIESCALAR { bless [] }
+    sub FETCH { "version" }
+    sub STORE { }
+    tie my $v, __PACKAGE__;
+    $v = version->new(1);
+    eval { version->new($v) };
+}
+pass('no crash with version->new($tied) where $tied returns "version"');
+
 1;
 
 __DATA__
diff --git a/util.c b/util.c
index 8b2e5f5..4a170aa 100644 (file)
--- a/util.c
+++ b/util.c
@@ -4857,7 +4857,8 @@ Perl_new_version(pTHX_ SV *ver)
     dVAR;
     SV * const rv = newSV(0);
     PERL_ARGS_ASSERT_NEW_VERSION;
-    if ( sv_derived_from(ver,"version") ) /* can just copy directly */
+    if ( sv_derived_from(ver,"version") && SvROK(ver) )
+        /* can just copy directly */
     {
        I32 key;
        AV * const av = newAV();