mirror of
https://github.com/python/cpython.git
synced 2025-08-04 08:59:19 +00:00
[3.13] gh-130163: Fix crashes related to PySys_GetObject() (GH-130503) (GH-130556)
The use of PySys_GetObject() and _PySys_GetAttr(), which return a borrowed
reference, has been replaced by using one of the following functions, which
return a strong reference and distinguish a missing attribute from an error:
_PySys_GetOptionalAttr(), _PySys_GetOptionalAttrString(),
_PySys_GetRequiredAttr(), and _PySys_GetRequiredAttrString().
(cherry picked from commit 0ef4ffeefd
)
This commit is contained in:
parent
b0d3f49195
commit
7c1b76fce8
23 changed files with 505 additions and 180 deletions
|
@ -32,6 +32,7 @@
|
|||
#include "pycore_typeobject.h" // _PySuper_Lookup()
|
||||
#include "pycore_uop_ids.h" // Uops
|
||||
#include "pycore_pyerrors.h"
|
||||
#include "pycore_sysmodule.h" // _PySys_GetOptionalAttrString()
|
||||
|
||||
#include "pycore_dict.h"
|
||||
#include "dictobject.h"
|
||||
|
@ -2805,13 +2806,18 @@ import_from(PyThreadState *tstate, PyObject *v, PyObject *name)
|
|||
}
|
||||
int is_possibly_shadowing_stdlib = 0;
|
||||
if (is_possibly_shadowing) {
|
||||
PyObject *stdlib_modules = PySys_GetObject("stdlib_module_names");
|
||||
PyObject *stdlib_modules;
|
||||
if (_PySys_GetOptionalAttrString("stdlib_module_names", &stdlib_modules) < 0) {
|
||||
goto done;
|
||||
}
|
||||
if (stdlib_modules && PyAnySet_Check(stdlib_modules)) {
|
||||
is_possibly_shadowing_stdlib = PySet_Contains(stdlib_modules, mod_name_or_unknown);
|
||||
if (is_possibly_shadowing_stdlib < 0) {
|
||||
Py_DECREF(stdlib_modules);
|
||||
goto done;
|
||||
}
|
||||
}
|
||||
Py_XDECREF(stdlib_modules);
|
||||
}
|
||||
|
||||
if (origin == NULL && PyModule_Check(v)) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue