Skip to content

Commit

Permalink
Fix segfault if Crypto.Random.new is missing for some reason.
Browse files Browse the repository at this point in the history
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).
  • Loading branch information
dlitz committed Feb 18, 2012
1 parent a6ddd10 commit 4b3c25f
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/_fastmath.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 4b3c25f

Please sign in to comment.