summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Misc/NEWS4
-rw-r--r--Python/pystate.c6
2 files changed, 8 insertions, 2 deletions
diff --git a/Misc/NEWS b/Misc/NEWS
index 7530624751..730ed96e61 100644
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -10,6 +10,10 @@ Release date: TBA
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 --git a/Python/pystate.c b/Python/pystate.c
index 6d1c6d0a1f..24e20c3e23 100644
--- a/Python/pystate.c
+++ b/Python/pystate.c
@@ -281,14 +281,16 @@ int
_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)