summaryrefslogtreecommitdiffstats
path: root/Python/import.c
diff options
context:
space:
mode:
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2023-07-27 21:51:34 (GMT)
committerGitHub <noreply@github.com>2023-07-27 21:51:34 (GMT)
commitabaf89d908304891c99c6a0450cf7e160c17cdd3 (patch)
treec05549d0e395f57e1a53eb47689b3e7d4ce0bb58 /Python/import.c
parent5daf19d763826a977a596b6fbc035ee03c0deafc (diff)
downloadcpython-abaf89d908304891c99c6a0450cf7e160c17cdd3.zip
cpython-abaf89d908304891c99c6a0450cf7e160c17cdd3.tar.gz
cpython-abaf89d908304891c99c6a0450cf7e160c17cdd3.tar.bz2
[3.12] gh-104621: Check for Incompatible Extensions in import_find_extension() (gh-107184) (gh-107360)
gh-104621: Check for Incompatible Extensions in import_find_extension() (gh-107184) This fixes a bug where incompatible modules could still be imported if attempted multiple times. (cherry picked from commit 75c974f5353685f338344618ad7344e64c2293d0) Co-authored-by: Eric Snow <ericsnowcurrently@gmail.com>
Diffstat (limited to 'Python/import.c')
-rw-r--r--Python/import.c21
1 files changed, 11 insertions, 10 deletions
diff --git a/Python/import.c b/Python/import.c
index d10c5ce..a93a645 100644
--- a/Python/import.c
+++ b/Python/import.c
@@ -1222,6 +1222,15 @@ import_find_extension(PyThreadState *tstate, PyObject *name,
return NULL;
}
+ /* It may have been successfully imported previously
+ in an interpreter that allows legacy modules
+ but is not allowed in the current interpreter. */
+ const char *name_buf = PyUnicode_AsUTF8(name);
+ assert(name_buf != NULL);
+ if (_PyImport_CheckSubinterpIncompatibleExtensionAllowed(name_buf) < 0) {
+ return NULL;
+ }
+
PyObject *mod, *mdict;
PyObject *modules = MODULES(tstate->interp);
@@ -3712,16 +3721,8 @@ _imp_create_dynamic_impl(PyObject *module, PyObject *spec, PyObject *file)
PyThreadState *tstate = _PyThreadState_GET();
mod = import_find_extension(tstate, name, path);
- if (mod != NULL) {
- const char *name_buf = PyUnicode_AsUTF8(name);
- assert(name_buf != NULL);
- if (_PyImport_CheckSubinterpIncompatibleExtensionAllowed(name_buf) < 0) {
- Py_DECREF(mod);
- mod = NULL;
- }
- goto finally;
- }
- else if (PyErr_Occurred()) {
+ if (mod != NULL || _PyErr_Occurred(tstate)) {
+ assert(mod == NULL || !_PyErr_Occurred(tstate));
goto finally;
}