dcb3b7
From fecd3be8dbdb747b9cbf4cbb9299ce40faabc8e6 Mon Sep 17 00:00:00 2001
dcb3b7
From: John Lightsey <lightsey@debian.org>
dcb3b7
Date: Mon, 14 Nov 2016 11:56:15 +0100
dcb3b7
Subject: [PATCH] Fix Storable segfaults.
dcb3b7
dcb3b7
Fix a null pointed dereference segfault in storable when the
dcb3b7
retrieve_code logic was unable to read the string that contained
dcb3b7
the code.
dcb3b7
dcb3b7
Also fix several locations where retrieve_other was called with a
dcb3b7
null context pointer. This also resulted in a null pointer
dcb3b7
dereference.
dcb3b7
---
dcb3b7
 dist/Storable/Storable.xs | 10 +++++++---
dcb3b7
 1 file changed, 7 insertions(+), 3 deletions(-)
dcb3b7
dcb3b7
diff --git a/dist/Storable/Storable.xs b/dist/Storable/Storable.xs
dcb3b7
index 053951c..caa489c 100644
dcb3b7
--- a/dist/Storable/Storable.xs
dcb3b7
+++ b/dist/Storable/Storable.xs
dcb3b7
@@ -5647,6 +5647,10 @@ static SV *retrieve_code(pTHX_ stcxt_t *cxt, const char *cname)
dcb3b7
 		CROAK(("Unexpected type %d in retrieve_code\n", type));
dcb3b7
 	}
dcb3b7
 
dcb3b7
+	if (!text) {
dcb3b7
+		CROAK(("Unable to retrieve code\n"));
dcb3b7
+	}
dcb3b7
+
dcb3b7
 	/*
dcb3b7
 	 * prepend "sub " to the source
dcb3b7
 	 */
dcb3b7
@@ -5767,7 +5771,7 @@ static SV *old_retrieve_array(pTHX_ stcxt_t *cxt, const char *cname)
dcb3b7
 			continue;			/* av_extend() already filled us with undef */
dcb3b7
 		}
dcb3b7
 		if (c != SX_ITEM)
dcb3b7
-			(void) retrieve_other(aTHX_ (stcxt_t *) 0, 0);	/* Will croak out */
dcb3b7
+			(void) retrieve_other(aTHX_ cxt, 0);	/* Will croak out */
dcb3b7
 		TRACEME(("(#%d) item", i));
dcb3b7
 		sv = retrieve(aTHX_ cxt, 0);						/* Retrieve item */
dcb3b7
 		if (!sv)
dcb3b7
@@ -5844,7 +5848,7 @@ static SV *old_retrieve_hash(pTHX_ stcxt_t *cxt, const char *cname)
dcb3b7
 			if (!sv)
dcb3b7
 				return (SV *) 0;
dcb3b7
 		} else
dcb3b7
-			(void) retrieve_other(aTHX_ (stcxt_t *) 0, 0);	/* Will croak out */
dcb3b7
+			(void) retrieve_other(aTHX_ cxt, 0);	/* Will croak out */
dcb3b7
 
dcb3b7
 		/*
dcb3b7
 		 * Get key.
dcb3b7
@@ -5855,7 +5859,7 @@ static SV *old_retrieve_hash(pTHX_ stcxt_t *cxt, const char *cname)
dcb3b7
 
dcb3b7
 		GETMARK(c);
dcb3b7
 		if (c != SX_KEY)
dcb3b7
-			(void) retrieve_other(aTHX_ (stcxt_t *) 0, 0);	/* Will croak out */
dcb3b7
+			(void) retrieve_other(aTHX_ cxt, 0);	/* Will croak out */
dcb3b7
 		RLEN(size);						/* Get key size */
dcb3b7
 		KBUFCHK((STRLEN)size);					/* Grow hash key read pool if needed */
dcb3b7
 		if (size)
dcb3b7
-- 
dcb3b7
2.10.2
dcb3b7