Skip to content

Commit c64b709

Browse files
author
Erlend E. Aasland
committed
bpo-28528: Harden pdb.checkline()
Test case C&P from T. Kluyver's patch. Co-written-by: Thomas Kluyver <[email protected]>
1 parent 103d5e4 commit c64b709

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

Lib/pdb.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -752,7 +752,10 @@ def checkline(self, filename, lineno):
752752
"""
753753
# this method should be callable before starting debugging, so default
754754
# to "no globals" if there is no current frame
755-
globs = self.curframe.f_globals if hasattr(self, 'curframe') else None
755+
try:
756+
globs = self.curframe.f_globals
757+
except AttributeError:
758+
globs = None
756759
line = linecache.getline(filename, lineno, globs)
757760
if not line:
758761
self.message('End of file')

Lib/test/test_pdb.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1806,6 +1806,14 @@ def test_issue42383(self):
18061806
expected = '(Pdb) The correct file was executed'
18071807
self.assertEqual(stdout.split('\n')[6].rstrip('\r'), expected)
18081808

1809+
def test_issue28528(self):
1810+
with open(os_helper.TESTFN, "w") as f:
1811+
f.write("print(123)")
1812+
db = pdb.Pdb()
1813+
self.assertEqual(db.checkline(os_helper.TESTFN, 1), 1)
1814+
db.reset()
1815+
self.assertEqual(db.checkline(os_helper.TESTFN, 1), 1)
1816+
18091817

18101818
def load_tests(*args):
18111819
from test import test_pdb

0 commit comments

Comments
 (0)