fix UAFs in register_lazy_on_parent

This commit is contained in:
Bénédikt Tran 2025-12-07 11:36:30 +01:00 committed by T. Wouters
parent 2a514d92a9
commit 74f35c42cb

View file

@ -4283,8 +4283,7 @@ register_lazy_on_parent(PyThreadState *tstate, PyObject *name, PyObject *builtin
} }
/* Add the lazy import for the child to the parent */ /* Add the lazy import for the child to the parent */
Py_XDECREF(parent_module); Py_XSETREF(parent_module, PyImport_GetModule(parent));
parent_module = PyImport_GetModule(parent);
if (parent_module == NULL) { if (parent_module == NULL) {
if (PyErr_Occurred()) { if (PyErr_Occurred()) {
goto done; goto done;
@ -4310,8 +4309,7 @@ register_lazy_on_parent(PyThreadState *tstate, PyObject *name, PyObject *builtin
} }
Py_DECREF(lazy_submodules); Py_DECREF(lazy_submodules);
} else { } else {
Py_XDECREF(parent_dict); Py_XSETREF(parent_dict, get_mod_dict(parent_module));
parent_dict = get_mod_dict(parent_module);
if (parent_dict == NULL) { if (parent_dict == NULL) {
goto done; goto done;
} }
@ -4334,8 +4332,7 @@ register_lazy_on_parent(PyThreadState *tstate, PyObject *name, PyObject *builtin
} }
} }
Py_DECREF(name); Py_SETREF(name, parent);
name = parent;
parent = NULL; parent = NULL;
} }