From: Tom Tromey Date: Tue, 15 Oct 2024 16:50:01 +0000 (-0600) Subject: Require a command argument in gdb.execute_mi X-Git-Tag: gdb-16-branchpoint~639 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=32af040ef2fcbeccf746acef230db826fad951f9;p=thirdparty%2Fbinutils-gdb.git Require a command argument in gdb.execute_mi Hannes pointed out that gdb.execute_mi() will crash. This patch fixes the bug. Reviewed-By: Guinevere Larsen --- diff --git a/gdb/python/py-mi.c b/gdb/python/py-mi.c index f0e28d9d818..cf75a18958e 100644 --- a/gdb/python/py-mi.c +++ b/gdb/python/py-mi.c @@ -143,6 +143,13 @@ gdbpy_execute_mi_command (PyObject *self, PyObject *args, PyObject *kw) if (n_args < 0) return nullptr; + if (n_args == 0) + { + PyErr_SetString (PyExc_TypeError, + _("gdb.execute_mi requires command argument")); + return nullptr; + } + for (Py_ssize_t i = 0; i < n_args; ++i) { /* Note this returns a borrowed reference. */ diff --git a/gdb/testsuite/gdb.python/py-exec-mi.exp b/gdb/testsuite/gdb.python/py-exec-mi.exp index 8a5d0c9da2f..6b81644c0c7 100644 --- a/gdb/testsuite/gdb.python/py-exec-mi.exp +++ b/gdb/testsuite/gdb.python/py-exec-mi.exp @@ -30,3 +30,7 @@ gdb_test_no_output "python gdb.execute_mi('-exec-arguments', 'a', 'b', 'c')" \ "set arguments" gdb_test "show args" ".*\"a b c\"." + +# Ensure that this causes an error, not a crash. +gdb_test "python gdb.execute_mi()" \ + "Error occurred in Python: gdb.execute_mi requires command argument"