Skip to content

Commit aaec54d

Browse files
committed
Don't pass the realpath of script target to system functions
1 parent 572c780 commit aaec54d

File tree

2 files changed

+13
-8
lines changed

2 files changed

+13
-8
lines changed

Lib/pdb.py

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -183,13 +183,17 @@ class _ExecutableTarget:
183183

184184
class _ScriptTarget(_ExecutableTarget):
185185
def __init__(self, target):
186-
self._target = os.path.realpath(target)
187-
188-
if not os.path.exists(self._target):
189-
print(f'Error: {target} does not exist')
186+
self._orig_target = target
187+
self._target = os.path.realpath(self._orig_target)
188+
189+
# Do not pass realpath to system functions, because it breaks
190+
# pseudofiles such as anonymous pipe symlinks from process substitution.
191+
# See GH-142315 for more details.
192+
if not os.path.exists(self._orig_target):
193+
print(f'Error: {self._orig_target} does not exist')
190194
sys.exit(1)
191-
if os.path.isdir(self._target):
192-
print(f'Error: {target} is a directory')
195+
if os.path.isdir(self._orig_target):
196+
print(f'Error: {self._orig_target} is a directory')
193197
sys.exit(1)
194198

195199
# If safe_path(-P) is not set, sys.path[0] is the directory
@@ -207,8 +211,8 @@ def filename(self):
207211
@property
208212
def code(self):
209213
# Open the file each time because the file may be modified
210-
with io.open_code(self._target) as fp:
211-
return f"exec(compile({fp.read()!r}, {self._target!r}, 'exec'))"
214+
with io.open_code(self._orig_target) as fp:
215+
return f"exec(compile({fp.read()!r}, {self._orig_target!r}, 'exec'))"
212216

213217
@property
214218
def namespace(self):
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Pdb can run scripts from pseudofiles. Patch by Bartosz Sławecki.

0 commit comments

Comments
 (0)