summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorandrei kulakov <andrei.avk@gmail.com>2021-07-28 16:55:03 (GMT)
committerGitHub <noreply@github.com>2021-07-28 16:55:03 (GMT)
commit53b9458f2e9314703a5406ca817d757f1509882a (patch)
tree19dd435240b7889eafbe710a528c381e95329c1a
parentcb1d76f10ab33dddd0dbd64e6506bf7c065d499b (diff)
downloadcpython-53b9458f2e9314703a5406ca817d757f1509882a.zip
cpython-53b9458f2e9314703a5406ca817d757f1509882a.tar.gz
cpython-53b9458f2e9314703a5406ca817d757f1509882a.tar.bz2
bpo-44682: Handle invalid arg to pdb's "commands" directive (#27252)
-rwxr-xr-xLib/pdb.py6
-rw-r--r--Lib/test/test_pdb.py11
-rw-r--r--Misc/NEWS.d/next/Library/2021-07-20-00-11-47.bpo-44682.3m2qVV.rst2
3 files changed, 19 insertions, 0 deletions
diff --git a/Lib/pdb.py b/Lib/pdb.py
index 8aa899f..d711007 100755
--- a/Lib/pdb.py
+++ b/Lib/pdb.py
@@ -640,6 +640,12 @@ class Pdb(bdb.Bdb, cmd.Cmd):
except:
self.error("Usage: commands [bnum]\n ...\n end")
return
+ try:
+ self.get_bpbynumber(bnum)
+ except ValueError as err:
+ self.error('cannot set commands: %s' % err)
+ return
+
self.commands_bnum = bnum
# Save old definitions for the case of a keyboard interrupt.
if bnum in self.commands:
diff --git a/Lib/test/test_pdb.py b/Lib/test/test_pdb.py
index 5794e67..5bb8069 100644
--- a/Lib/test/test_pdb.py
+++ b/Lib/test/test_pdb.py
@@ -260,6 +260,9 @@ def test_pdb_breakpoint_commands():
... 'tbreak 5',
... 'continue', # will stop at temporary breakpoint
... 'break', # make sure breakpoint is gone
+ ... 'commands 10', # out of range
+ ... 'commands a', # display help
+ ... 'commands 4', # already deleted
... 'continue',
... ]):
... test_function()
@@ -319,6 +322,14 @@ def test_pdb_breakpoint_commands():
> <doctest test.test_pdb.test_pdb_breakpoint_commands[0]>(5)test_function()
-> print(3)
(Pdb) break
+ (Pdb) commands 10
+ *** cannot set commands: Breakpoint number 10 out of range
+ (Pdb) commands a
+ *** Usage: commands [bnum]
+ ...
+ end
+ (Pdb) commands 4
+ *** cannot set commands: Breakpoint 4 already deleted
(Pdb) continue
3
4
diff --git a/Misc/NEWS.d/next/Library/2021-07-20-00-11-47.bpo-44682.3m2qVV.rst b/Misc/NEWS.d/next/Library/2021-07-20-00-11-47.bpo-44682.3m2qVV.rst
new file mode 100644
index 0000000..308053a
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2021-07-20-00-11-47.bpo-44682.3m2qVV.rst
@@ -0,0 +1,2 @@
+Change the :mod:`pdb` *commands* directive to disallow setting commands
+for an invalid breakpoint and to display an appropriate error.