[PATCH] Fix a NULL pointer dereference when looking for a DESTROY method
Niko Tyni
ntyni at debian.org
Fri Jan 8 19:21:57 UTC 2010
The empty DESTROY method optimization introduced by commit
fbb3ee5af3d would crash the interpreter if a DESTROY method
was declared but not actually defined.
This is seen in the real world with AutoLoader / AutoSplit,
where the crash defeats autoloading a DESTROY method.
---
sv.c | 3 ++-
t/op/method.t | 11 ++++++++++-
2 files changed, 12 insertions(+), 2 deletions(-)
diff --git a/sv.c b/sv.c
index fb82caf..ed4be5f 100644
--- a/sv.c
+++ b/sv.c
@@ -5658,7 +5658,8 @@ Perl_sv_clear(pTHX_ register SV *const sv)
&& !CvCONST(destructor)
/* Don't bother calling an empty destructor */
&& (CvISXSUB(destructor)
- || CvSTART(destructor)->op_next->op_type != OP_LEAVESUB))
+ || (CvSTART(destructor)
+ && (CvSTART(destructor)->op_next->op_type != OP_LEAVESUB))))
{
SV* const tmpref = newRV(sv);
SvREADONLY_on(tmpref); /* DESTROY() could be naughty */
diff --git a/t/op/method.t b/t/op/method.t
index afa8cfb..d2914c4 100644
--- a/t/op/method.t
+++ b/t/op/method.t
@@ -10,7 +10,7 @@ BEGIN {
require "test.pl";
}
-print "1..78\n";
+print "1..79\n";
@A::ISA = 'B';
@B::ISA = 'C';
@@ -292,3 +292,12 @@ EOT
"check if UNIVERSAL::AUTOLOAD works",
);
}
+{
+ fresh_perl_is(<<'EOT',
+sub M::DESTROY; bless {}, "M" ; print "survived\n";
+EOT
+ "survived",
+ {},
+ "no crash with a declared but missing DESTROY method"
+ );
+}
--
1.6.6
--IS0zKkzwUGydFO0o--
More information about the Perl-maintainers
mailing list