Blob Blame History Raw
From 4b3c25f4b872c288ace179c68cebc46cce5039aa Mon Sep 17 00:00:00 2001
From: "Dwayne C. Litzenberger" <dlitz@dlitz.net>
Date: Sat, 18 Feb 2012 12:51:11 -0500
Subject: [PATCH 3/3] Fix segfault if Crypto.Random.new is missing for some
 reason.

This should never happen, but we're already checking that Crypto.Random.new is
callable, so we might as well also check that Crypto.Random.new exists.  Also,
fixing this should silence an (arguably false-positive) error emitted by
cpychecker (a static analysis tool used by the Fedora project).
---
 src/_fastmath.c |    5 +++++
 1 files changed, 5 insertions(+), 0 deletions(-)

diff --git a/src/_fastmath.c b/src/_fastmath.c
index 8c1a517..4b5dede 100644
--- a/src/_fastmath.c
+++ b/src/_fastmath.c
@@ -1136,6 +1136,11 @@ getRNG (void)
 	module_dict = PyModule_GetDict (module);
 	Py_DECREF (module);
 	new_func = PyDict_GetItemString (module_dict, "new");
+	if (new_func == NULL) {
+		PyErr_SetString (PyExc_RuntimeError,
+						 "Crypto.Random.new is missing.");
+		return NULL;
+	}
 	if (!PyCallable_Check (new_func))
 	{
 		PyErr_SetString (PyExc_RuntimeError,
-- 
1.7.7.6