diff options
author | Benjamin Peterson <benjamin@python.org> | 2019-09-11 23:43:22 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-09-11 23:43:22 (GMT) |
commit | 39de95b746c990e6a2fe9af5fad01747f58b2e5f (patch) | |
tree | e493945a5beed10740ec8711b7579f3bdc5edf02 /Python | |
parent | ee536b2020b1f0baad1286dbd4345e13870324af (diff) | |
download | cpython-39de95b746c990e6a2fe9af5fad01747f58b2e5f.zip cpython-39de95b746c990e6a2fe9af5fad01747f58b2e5f.tar.gz cpython-39de95b746c990e6a2fe9af5fad01747f58b2e5f.tar.bz2 |
closes bpo-38124: Fix bounds check in PyState_AddModule. (GH-16007)
The >=, checking whether a module index was in already in the module-by-index list, needed to be strict.
Also, fold nested ifs into one and fix some bad spacing.
Diffstat (limited to 'Python')
-rw-r--r-- | Python/pystate.c | 14 |
1 files changed, 6 insertions, 8 deletions
diff --git a/Python/pystate.c b/Python/pystate.c index 02bc903..7dd8b7f 100644 --- a/Python/pystate.c +++ b/Python/pystate.c @@ -684,7 +684,7 @@ _PyState_AddModule(PyObject* module, struct PyModuleDef* def) if (!state->modules_by_index) return -1; } - while(PyList_GET_SIZE(state->modules_by_index) <= def->m_base.m_index) + while (PyList_GET_SIZE(state->modules_by_index) <= def->m_base.m_index) if (PyList_Append(state->modules_by_index, Py_None) < 0) return -1; Py_INCREF(module); @@ -702,13 +702,11 @@ PyState_AddModule(PyObject* module, struct PyModuleDef* def) return -1; } index = def->m_base.m_index; - if (state->modules_by_index) { - if(PyList_GET_SIZE(state->modules_by_index) >= index) { - if(module == PyList_GET_ITEM(state->modules_by_index, index)) { - Py_FatalError("PyState_AddModule: Module already added!"); - return -1; - } - } + if (state->modules_by_index && + index < PyList_GET_SIZE(state->modules_by_index) && + module == PyList_GET_ITEM(state->modules_by_index, index)) { + Py_FatalError("PyState_AddModule: Module already added!"); + return -1; } return _PyState_AddModule(module, def); } |