]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
gdb/python: don't allow the user to delete window title attributes
authorAndrew Burgess <andrew.burgess@embecosm.com>
Mon, 8 Feb 2021 11:44:51 +0000 (11:44 +0000)
committerAndrew Burgess <andrew.burgess@embecosm.com>
Mon, 8 Feb 2021 11:55:05 +0000 (11:55 +0000)
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.

gdb/ChangeLog
gdb/python/py-tui.c
gdb/testsuite/ChangeLog
gdb/testsuite/gdb.python/tui-window.exp
gdb/testsuite/gdb.python/tui-window.py

index d450be6433dc4b3344a71662644c7e91e22d1806..b7b4909f84bedb8ffd00ccb559d6ebaa1af89cf3 100644 (file)
@@ -1,3 +1,8 @@
+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.
index 6e9a1462ec59f4c774463bc6374a43cb1bf99606..73b73f33d4af6a078913f4ed6647530ac9c08ec9 100644 (file)
@@ -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;
index de68598dc5ffa7991ec98e6e026cbc1d22b9eba2..faee2c426379f216516ecee5754b6326dcbe4ce6 100644 (file)
@@ -1,3 +1,11 @@
+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.
index 13e14be06546aa9073aee15c919876c161420c3e..8d86afb14496bbf732c9bdd91c9cdf0a93c65d8e 100644 (file)
@@ -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"
index 88a1b06f12c5ac9ea36365647d844e9623d9f40b..3bea78846ae86198240d143586e9c1b1982e5f3e 100644 (file)
@@ -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")