Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[3.14] gh-134100: Fix use-after-free inPyImport_ImportModuleLevelObject (GH-134117)#134171

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes fromall commits
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
15 changes: 15 additions & 0 deletionsLib/test/test_importlib/import_/test_relative_imports.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -223,6 +223,21 @@ def test_relative_import_no_package_exists_absolute(self):
self.__import__('sys', {'__package__': '', '__spec__': None},
level=1)

def test_malicious_relative_import(self):
# https://github.com/python/cpython/issues/134100
# Test to make sure UAF bug with error msg doesn't come back to life
import sys
loooong = "".ljust(0x23000, "b")
name = f"a.{loooong}.c"

with util.uncache(name):
sys.modules[name] = {}
with self.assertRaisesRegex(
KeyError,
r"'a\.b+' not in sys\.modules as expected"
):
__import__(f"{loooong}.c", {"__package__": "a"}, level=1)


(Frozen_RelativeImports,
Source_RelativeImports
Expand Down
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
Fix a use-after-free bug that occurs when an imported module isn't
in :data:`sys.modules` after its initial import. Patch by Nico-Posada.
4 changes: 3 additions & 1 deletionPython/import.c
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -3852,15 +3852,17 @@ PyImport_ImportModuleLevelObject(PyObject *name, PyObject *globals,
}

final_mod = import_get_module(tstate, to_return);
Py_DECREF(to_return);
if (final_mod == NULL) {
if (!_PyErr_Occurred(tstate)) {
_PyErr_Format(tstate, PyExc_KeyError,
"%R not in sys.modules as expected",
to_return);
}
Py_DECREF(to_return);
goto error;
}

Py_DECREF(to_return);
}
}
else {
Expand Down
Loading

[8]ページ先頭

©2009-2025 Movatter.jp