diff options
author | Andrew Burgess <andrew.burgess@embecosm.com> | 2021-02-08 11:44:51 +0000 |
---|---|---|
committer | Andrew Burgess <andrew.burgess@embecosm.com> | 2021-02-08 11:55:05 +0000 |
commit | e0c23e11da18b615c382888da8e978f16428e81b (patch) | |
tree | 92997a5c1c428d3efa2d645d75a0823903388d09 | |
parent | 1cf2399651ef3fe1350ad8276cf00d16ddeb9960 (diff) | |
download | gdb-e0c23e11da18b615c382888da8e978f16428e81b.zip gdb-e0c23e11da18b615c382888da8e978f16428e81b.tar.gz gdb-e0c23e11da18b615c382888da8e978f16428e81b.tar.bz2 |
gdb/python: don't allow the user to delete window title attributes
There's a bug in the python tui API. If the user tries to delete the
window title attribute then this will trigger undefined behaviour in
GDB due to a missing nullptr check.
gdb/ChangeLog:
* python/py-tui.c (gdbpy_tui_set_title): Check that the new value
for the title is not nullptr.
gdb/testsuite/ChangeLog:
* gdb.python/tui-window.exp: Add new tests.
* gdb.python/tui-window.py (TestWindow) <__init__>: Store
TestWindow object into global the_window.
<remote_title>: New method.
(delete_window_title): New function.
-rw-r--r-- | gdb/ChangeLog | 5 | ||||
-rw-r--r-- | gdb/python/py-tui.c | 2 | ||||
-rw-r--r-- | gdb/testsuite/ChangeLog | 8 | ||||
-rw-r--r-- | gdb/testsuite/gdb.python/tui-window.exp | 6 | ||||
-rw-r--r-- | gdb/testsuite/gdb.python/tui-window.py | 10 |
5 files changed, 29 insertions, 2 deletions
diff --git a/gdb/ChangeLog b/gdb/ChangeLog index d450be6..b7b4909 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,5 +1,10 @@ 2021-02-08 Andrew Burgess <andrew.burgess@embecosm.com> + * python/py-tui.c (gdbpy_tui_set_title): Check that the new value + for the title is not nullptr. + +2021-02-08 Andrew Burgess <andrew.burgess@embecosm.com> + * tui-layout.c (saved_tui_windows): Delete. (tui_apply_current_layout): Don't make use of saved_tui_windows, call new get_windows member function instead. diff --git a/gdb/python/py-tui.c b/gdb/python/py-tui.c index 6e9a146..73b73f3 100644 --- a/gdb/python/py-tui.c +++ b/gdb/python/py-tui.c @@ -434,7 +434,7 @@ gdbpy_tui_set_title (PyObject *self, PyObject *newvalue, void *closure) return -1; } - if (win->window == nullptr) + if (newvalue == nullptr) { PyErr_Format (PyExc_TypeError, _("Cannot delete \"title\" attribute.")); return -1; diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog index de68598..faee2c4 100644 --- a/gdb/testsuite/ChangeLog +++ b/gdb/testsuite/ChangeLog @@ -1,5 +1,13 @@ 2021-02-08 Andrew Burgess <andrew.burgess@embecosm.com> + * gdb.python/tui-window.exp: Add new tests. + * gdb.python/tui-window.py (TestWindow) <__init__>: Store + TestWindow object into global the_window. + <remote_title>: New method. + (delete_window_title): New function. + +2021-02-08 Andrew Burgess <andrew.burgess@embecosm.com> + * gdb.tui/winheight.exp: Add more tests. 2021-02-08 Andrew Burgess <andrew.burgess@embecosm.com> diff --git a/gdb/testsuite/gdb.python/tui-window.exp b/gdb/testsuite/gdb.python/tui-window.exp index 13e14be..8d86afb 100644 --- a/gdb/testsuite/gdb.python/tui-window.exp +++ b/gdb/testsuite/gdb.python/tui-window.exp @@ -47,6 +47,12 @@ Term::check_contents "test title" \ "This Is The Title" Term::check_contents "Window display" "Test: 0" +Term::command "python delete_window_title ()" +Term::check_contents "error message after trying to delete title" \ + "TypeError: Cannot delete \"title\" attribute\\." +Term::check_contents "title is unchanged" \ + "This Is The Title" + Term::resize 51 51 # Remember that a resize request actually does two resizes... Term::check_contents "Window was updated" "Test: 2" diff --git a/gdb/testsuite/gdb.python/tui-window.py b/gdb/testsuite/gdb.python/tui-window.py index 88a1b06..3bea788 100644 --- a/gdb/testsuite/gdb.python/tui-window.py +++ b/gdb/testsuite/gdb.python/tui-window.py @@ -22,7 +22,7 @@ the_window = None class TestWindow: def __init__(self, win): global the_window - the_window = win + the_window = self self.count = 0 self.win = win win.title = "This Is The Title" @@ -34,8 +34,16 @@ class TestWindow: self.win.write("Test: " + str(self.count) + " " + str(w) + "x" + str(h)) self.count = self.count + 1 + # Tries to delete the title attribute. GDB will throw an error. + def remove_title(self): + del self.win.title + gdb.register_window_type("test", TestWindow) +# Call REMOVE_TITLE on the global window object. +def delete_window_title (): + the_window.remove_title () + # A TUI window "constructor" that always fails. def failwin(win): raise RuntimeError("Whoops") |