Skip to content

Commit 74f35c4

Browse files
picnixzYhg1s
authored andcommitted
fix UAFs in register_lazy_on_parent
1 parent 2a514d9 commit 74f35c4

File tree

1 file changed

+3
-6
lines changed

1 file changed

+3
-6
lines changed

Python/import.c

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4283,8 +4283,7 @@ register_lazy_on_parent(PyThreadState *tstate, PyObject *name, PyObject *builtin
42834283
}
42844284

42854285
/* Add the lazy import for the child to the parent */
4286-
Py_XDECREF(parent_module);
4287-
parent_module = PyImport_GetModule(parent);
4286+
Py_XSETREF(parent_module, PyImport_GetModule(parent));
42884287
if (parent_module == NULL) {
42894288
if (PyErr_Occurred()) {
42904289
goto done;
@@ -4310,8 +4309,7 @@ register_lazy_on_parent(PyThreadState *tstate, PyObject *name, PyObject *builtin
43104309
}
43114310
Py_DECREF(lazy_submodules);
43124311
} else {
4313-
Py_XDECREF(parent_dict);
4314-
parent_dict = get_mod_dict(parent_module);
4312+
Py_XSETREF(parent_dict, get_mod_dict(parent_module));
43154313
if (parent_dict == NULL) {
43164314
goto done;
43174315
}
@@ -4334,8 +4332,7 @@ register_lazy_on_parent(PyThreadState *tstate, PyObject *name, PyObject *builtin
43344332
}
43354333
}
43364334

4337-
Py_DECREF(name);
4338-
name = parent;
4335+
Py_SETREF(name, parent);
43394336
parent = NULL;
43404337
}
43414338

0 commit comments

Comments
 (0)