Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 4b7b565

Browse files
committed
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.
1 parent 8447965 commit 4b7b565

2 files changed

Lines changed: 8 additions & 2 deletions

File tree

Misc/NEWS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ Release date: TBA
1010
Core and Builtins
1111
-----------------
1212

13+
- Issue #27587: Fix another issue found by PVS-Studio: Null pointer check
14+
after use of 'def' in _PyState_AddModule().
15+
Initial patch by Christian Heimes.
16+
1317
- Issue #27782: Multi-phase extension module import now correctly allows the
1418
``m_methods`` field to be used to add module level functions to instances
1519
of non-module types returned from ``Py_create_mod``. Patch by Xiang Zhang.

Python/pystate.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -281,14 +281,16 @@ int
281281
_PyState_AddModule(PyObject* module, struct PyModuleDef* def)
282282
{
283283
PyInterpreterState *state;
284+
if (!def) {
285+
assert(PyErr_Occurred());
286+
return -1;
287+
}
284288
if (def->m_slots) {
285289
PyErr_SetString(PyExc_SystemError,
286290
"PyState_AddModule called on module with slots");
287291
return -1;
288292
}
289293
state = GET_INTERP_STATE();
290-
if (!def)
291-
return -1;
292294
if (!state->modules_by_index) {
293295
state->modules_by_index = PyList_New(0);
294296
if (!state->modules_by_index)

0 commit comments

Comments
 (0)