Skip to content

Commit 6779597

Browse files
committed
Restore _safe_realpath.
1 parent 03eae7e commit 6779597

1 file changed

Lines changed: 13 additions & 1 deletion

File tree

Lib/pdb.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ class _ExecutableTarget:
184184
class _ScriptTarget(_ExecutableTarget):
185185
def __init__(self, target):
186186
self._check(target)
187-
self._target = os.path.realpath(target)
187+
self._target = self._safe_realpath(target)
188188

189189
# If PYTHONSAFEPATH (-P) is not set, sys.path[0] is the directory
190190
# of pdb, and we should replace it with the directory of the script
@@ -203,6 +203,18 @@ def _check(target):
203203
print(f'Error: {target} is a directory')
204204
sys.exit(1)
205205

206+
@staticmethod
207+
def _safe_realpath(path):
208+
"""
209+
Return the canonical path (realpath) if it is accessible from the userspace.
210+
Otherwise (for example, if the path is a symlink to an anonymous pipe),
211+
return the original path.
212+
213+
See GH-142315.
214+
"""
215+
realpath = os.path.realpath(path)
216+
return realpath if os.path.exists(realpath) else path
217+
206218
def __repr__(self):
207219
return self._target
208220

0 commit comments

Comments
 (0)