From: Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> Date: Thu, 10 Oct 2024 09:35:47 +0000 (+0200) Subject: [3.13] gh-125140: Remove the current directory from sys.path when using pyrepl (GH... X-Git-Tag: v3.13.1~344 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=85cf3a9dbe752a04d502f1af815063e6c429e402;p=thirdparty%2FPython%2Fcpython.git [3.13] gh-125140: Remove the current directory from sys.path when using pyrepl (GH-125212) (#125224) --- diff --git a/Lib/site.py b/Lib/site.py index d31bc7723341..34e7d19f376c 100644 --- a/Lib/site.py +++ b/Lib/site.py @@ -503,9 +503,14 @@ def register_readline(): if PYTHON_BASIC_REPL: CAN_USE_PYREPL = False else: - import _pyrepl.readline - import _pyrepl.unix_console - from _pyrepl.main import CAN_USE_PYREPL + original_path = sys.path + sys.path = [p for p in original_path if p != ''] + try: + import _pyrepl.readline + import _pyrepl.unix_console + from _pyrepl.main import CAN_USE_PYREPL + finally: + sys.path = original_path except ImportError: return diff --git a/Misc/NEWS.d/next/Security/2024-10-09-20-08-13.gh-issue-125140.YgNWRB.rst b/Misc/NEWS.d/next/Security/2024-10-09-20-08-13.gh-issue-125140.YgNWRB.rst new file mode 100644 index 000000000000..f4a493023726 --- /dev/null +++ b/Misc/NEWS.d/next/Security/2024-10-09-20-08-13.gh-issue-125140.YgNWRB.rst @@ -0,0 +1 @@ +Remove the current directory from ``sys.path`` when using PyREPL.