diff options
author | Pablo Galindo Salgado <Pablogsal@gmail.com> | 2024-10-09 22:30:56 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-10-09 22:30:56 (GMT) |
commit | c7d5d1d93b630e352abd9a0c93ea6d34c443f444 (patch) | |
tree | 65520816c8a2d51f83eab373267d23cd7dd12412 | |
parent | 1877543d03d323d581b5fc0f19eff501926ba151 (diff) | |
download | cpython-c7d5d1d93b630e352abd9a0c93ea6d34c443f444.zip cpython-c7d5d1d93b630e352abd9a0c93ea6d34c443f444.tar.gz cpython-c7d5d1d93b630e352abd9a0c93ea6d34c443f444.tar.bz2 |
gh-125140: Remove the current directory from sys.path when using pyrepl (GH-125212)
Signed-off-by: Pablo Galindo <pablogsal@gmail.com>
Co-authored-by: Ćukasz Langa <lukasz@langa.pl>
Co-authored-by: Peter Bierma <zintensitydev@gmail.com>
-rw-r--r-- | Lib/site.py | 11 | ||||
-rw-r--r-- | Misc/NEWS.d/next/Security/2024-10-09-20-08-13.gh-issue-125140.YgNWRB.rst | 1 |
2 files changed, 9 insertions, 3 deletions
diff --git a/Lib/site.py b/Lib/site.py index b3194d7..07a6361 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 0000000..f4a4930 --- /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. |