Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Check for incompatible extensions in import_find_extension().
  • Loading branch information
ericsnowcurrently committed Jul 24, 2023
commit 44ae57f9c94019230155df39ea5ab208590732ef
20 changes: 10 additions & 10 deletions Python/import.c
Original file line number Diff line number Diff line change
Expand Up @@ -1226,6 +1226,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);

Expand Down Expand Up @@ -3715,16 +3724,7 @@ _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)) {
Comment thread
erlend-aasland marked this conversation as resolved.
goto finally;
}

Expand Down