From bc4eb4d6f895e86a4afbc016eae943c7546c35f2 Mon Sep 17 00:00:00 2001 From: Father Chrysostomos Date: Tue, 22 Nov 2011 21:28:15 -0800 Subject: [PATCH] [perl #102586] version->new("version") SEGVs 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 | 2 +- lib/version.t | 13 +++++++++++++ util.c | 3 ++- 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/ext/arybase/arybase.pm b/ext/arybase/arybase.pm index 829f2db..aa3946d 100644 --- a/ext/arybase/arybase.pm +++ b/ext/arybase/arybase.pm @@ -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. diff --git a/lib/version.t b/lib/version.t index dd47e87..da11023 100644 --- a/lib/version.t +++ b/lib/version.t @@ -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 --- 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(); -- 2.7.4