aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Tromey <tom@tromey.com>2018-09-07 19:28:39 -0600
committerTom Tromey <tom@tromey.com>2018-09-14 21:56:41 -0600
commita3a6aef4090ca13d065d116f5d77f4e3f7bcbf9a (patch)
tree20cde96408daf4d09951dad8e4f905a93f063746
parentf70e088ff4ebf79a4bea45e84a8b042706e6e083 (diff)
downloadgdb-a3a6aef4090ca13d065d116f5d77f4e3f7bcbf9a.zip
gdb-a3a6aef4090ca13d065d116f5d77f4e3f7bcbf9a.tar.gz
gdb-a3a6aef4090ca13d065d116f5d77f4e3f7bcbf9a.tar.bz2
Fix possible exception leak in python.c
In the Python code, gdb exceptions may not leak into the Python core. execute_gdb_command was calling bpstat_do_actions outside of a TRY/CATCH; which seemed risky. I don't have a test case for this, but if bpstat_do_actions could ever throw, it could crash gdb. This patch introduces a new scope in order to preserve the current semantics, so it is looks a bit bigger than it really is. Tested on x86-64 Fedora 28. gdb/ChangeLog 2018-09-07 Tom Tromey <tom@tromey.com> * python/python.c (execute_gdb_command): Call bpstat_do_actions inside the TRY.
-rw-r--r--gdb/ChangeLog5
-rw-r--r--gdb/python/python.c33
2 files changed, 23 insertions, 15 deletions
diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 6fe0526..80e1ccd 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,8 @@
+2018-09-07 Tom Tromey <tom@tromey.com>
+
+ * python/python.c (execute_gdb_command): Call bpstat_do_actions
+ inside the TRY.
+
2018-09-14 Sandra Loosemore <sandra@codesourcery.com>
* nios2-tdep.c (nios2_type_align): New.
diff --git a/gdb/python/python.c b/gdb/python/python.c
index 371f4a5..e89c90f 100644
--- a/gdb/python/python.c
+++ b/gdb/python/python.c
@@ -602,21 +602,27 @@ execute_gdb_command (PyObject *self, PyObject *args, PyObject *kw)
counted_command_line lines = read_command_lines_1 (reader, 1, nullptr);
- scoped_restore save_async = make_scoped_restore (&current_ui->async, 0);
+ {
+ scoped_restore save_async = make_scoped_restore (&current_ui->async,
+ 0);
- scoped_restore save_uiout = make_scoped_restore (&current_uiout);
+ scoped_restore save_uiout = make_scoped_restore (&current_uiout);
- /* Use the console interpreter uiout to have the same print format
- for console or MI. */
- interp = interp_lookup (current_ui, "console");
- current_uiout = interp->interp_ui_out ();
+ /* Use the console interpreter uiout to have the same print format
+ for console or MI. */
+ interp = interp_lookup (current_ui, "console");
+ current_uiout = interp->interp_ui_out ();
- scoped_restore preventer = prevent_dont_repeat ();
- if (to_string)
- to_string_res = execute_control_commands_to_string (lines.get (),
- from_tty);
- else
- execute_control_commands (lines.get (), from_tty);
+ scoped_restore preventer = prevent_dont_repeat ();
+ if (to_string)
+ to_string_res = execute_control_commands_to_string (lines.get (),
+ from_tty);
+ else
+ execute_control_commands (lines.get (), from_tty);
+ }
+
+ /* Do any commands attached to breakpoint we stopped at. */
+ bpstat_do_actions ();
}
CATCH (except, RETURN_MASK_ALL)
{
@@ -624,9 +630,6 @@ execute_gdb_command (PyObject *self, PyObject *args, PyObject *kw)
}
END_CATCH
- /* Do any commands attached to breakpoint we stopped at. */
- bpstat_do_actions ();
-
if (to_string)
return PyString_FromString (to_string_res.c_str ());
Py_RETURN_NONE;