Unverified Kaydet (Commit) 95d630e2 authored tarafından Pablo Galindo's avatar Pablo Galindo Kaydeden (comit) GitHub

bpo-34408: Prevent a null pointer dereference and resource leakage in…

bpo-34408: Prevent a null pointer dereference and resource leakage in `PyInterpreterState_New()` (GH-8767)

* A pointer in `PyInterpreterState_New()` could have been `NULL` when being dereferenced.

* Memory was leaked in `PyInterpreterState_New()` when taking some error-handling code path.
üst 745c0f39
Prevent a null pointer dereference and resource leakage in ``PyInterpreterState_New()``.
...@@ -172,23 +172,27 @@ PyInterpreterState_New(void) ...@@ -172,23 +172,27 @@ PyInterpreterState_New(void)
interp->pyexitmodule = NULL; interp->pyexitmodule = NULL;
HEAD_LOCK(); HEAD_LOCK();
interp->next = _PyRuntime.interpreters.head;
if (_PyRuntime.interpreters.main == NULL) {
_PyRuntime.interpreters.main = interp;
}
_PyRuntime.interpreters.head = interp;
if (_PyRuntime.interpreters.next_id < 0) { if (_PyRuntime.interpreters.next_id < 0) {
/* overflow or Py_Initialize() not called! */ /* overflow or Py_Initialize() not called! */
PyErr_SetString(PyExc_RuntimeError, PyErr_SetString(PyExc_RuntimeError,
"failed to get an interpreter ID"); "failed to get an interpreter ID");
/* XXX deallocate! */ PyMem_RawFree(interp);
interp = NULL; interp = NULL;
} else { } else {
interp->id = _PyRuntime.interpreters.next_id; interp->id = _PyRuntime.interpreters.next_id;
_PyRuntime.interpreters.next_id += 1; _PyRuntime.interpreters.next_id += 1;
interp->next = _PyRuntime.interpreters.head;
if (_PyRuntime.interpreters.main == NULL) {
_PyRuntime.interpreters.main = interp;
}
_PyRuntime.interpreters.head = interp;
} }
HEAD_UNLOCK(); HEAD_UNLOCK();
if (interp == NULL) {
return NULL;
}
interp->tstate_next_unique_id = 0; interp->tstate_next_unique_id = 0;
return interp; return interp;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment