(original) (raw)
changeset: 102839:51627344fc58 branch: 3.5 parent: 102833:7eea5b87f5fa user: Berker Peksag berker.peksag@gmail.com date: Mon Aug 22 18:05:56 2016 +0300 files: Misc/NEWS Python/pystate.c description: Issue #27587: Move null pointer check earlier in _PyState_AddModule() This was found by PVS-Studio: V595 The 'def' pointer was utilized before it was verified against nullptr. Check lines: 286, 292. pystate.c 286 Initial patch by Christian Heimes. diff -r 7eea5b87f5fa -r 51627344fc58 Misc/NEWS --- a/Misc/NEWS Mon Aug 22 10:50:53 2016 +0100 +++ b/Misc/NEWS Mon Aug 22 18:05:56 2016 +0300 @@ -10,6 +10,10 @@ Core and Builtins ----------------- +- Issue #27587: Fix another issue found by PVS-Studio: Null pointer check + after use of 'def' in _PyState_AddModule(). + Initial patch by Christian Heimes. + - Issue #27782: Multi-phase extension module import now correctly allows the ``m_methods`` field to be used to add module level functions to instances of non-module types returned from ``Py_create_mod``. Patch by Xiang Zhang. diff -r 7eea5b87f5fa -r 51627344fc58 Python/pystate.c --- a/Python/pystate.c Mon Aug 22 10:50:53 2016 +0100 +++ b/Python/pystate.c Mon Aug 22 18:05:56 2016 +0300 @@ -281,14 +281,16 @@ _PyState_AddModule(PyObject* module, struct PyModuleDef* def) { PyInterpreterState *state; + if (!def) { + assert(PyErr_Occurred()); + return -1; + } if (def->m_slots) { PyErr_SetString(PyExc_SystemError, "PyState_AddModule called on module with slots"); return -1; } state = GET_INTERP_STATE(); - if (!def) - return -1; if (!state->modules_by_index) { state->modules_by_index = PyList_New(0); if (!state->modules_by_index) /berker.peksag@gmail.com