assert nested CV existence when freeing CV
authorZefram <zefram@fysh.org>
Sat, 30 Dec 2017 12:36:54 +0000 (12:36 +0000)
committerZefram <zefram@fysh.org>
Sat, 30 Dec 2017 12:36:54 +0000 (12:36 +0000)
[perl #131631] has a convoluted test case that messes up parser error
recovery and causes a segv via null pointer dereference.  Turn the segv
into an assertion failure, by asserting non-nullness of the pointer.
This doesn't fix the actual problem with error recovery.

pad.c

diff --git a/pad.c b/pad.c
index d1311e2..6ec2e89 100644 (file)
--- a/pad.c
+++ b/pad.c
@@ -395,9 +395,11 @@ Perl_cv_undef_flags(pTHX_ CV *cv, U32 flags)
                if (name && PadnamePV(name) && *PadnamePV(name) == '&')
                    {
                        CV * const innercv = MUTABLE_CV(curpad[ix]);
-                       U32 inner_rc = SvREFCNT(innercv);
-                       assert(inner_rc);
+                       U32 inner_rc;
+                       assert(innercv);
                        assert(SvTYPE(innercv) != SVt_PVFM);
+                       inner_rc = SvREFCNT(innercv);
+                       assert(inner_rc);
 
                        if (SvREFCNT(comppad) < 2) { /* allow for /(?{ sub{} })/  */
                            curpad[ix] = NULL;