From: Andrew Burgess <andrew.burgess@embecosm.com>
To: Tom Tromey <tom@tromey.com>
Cc: Hannes Domani <ssbssa@yahoo.de>,
"gdb-patches@sourceware.org" <gdb-patches@sourceware.org>
Subject: Re: [PATCH 2/4] Return true in TuiWindow.is_valid only if TUI is enabled
Date: Mon, 8 Feb 2021 11:58:38 +0000 [thread overview]
Message-ID: <20210208115838.GF265215@embecosm.com> (raw)
In-Reply-To: <87ft29x9yn.fsf@tromey.com>
* Tom Tromey <tom@tromey.com> [2021-02-06 12:38:56 -0700]:
> >>>>> "Andrew" == Andrew Burgess <andrew.burgess@embecosm.com> writes:
>
> Andrew> gdb/ChangeLog:
>
> Andrew> * python/py-tui.c (gdbpy_tui_window) <is_valid>: New member
> Andrew> function.
> Andrew> (REQUIRE_WINDOW): Call is_valid member function.
> Andrew> (REQUIRE_WINDOW_FOR_SETTER): New define.
> Andrew> (gdbpy_tui_is_valid): Call is_valid member function.
> Andrew> (gdbpy_tui_set_title): Remove duplicate error checking, call
> Andrew> REQUIRE_WINDOW_FOR_SETTER instead.
> Andrew> * tui/tui-data.h (struct tui_win_info) <is_visible>: Check
> Andrew> tui_active too.
> Andrew> * tui/tui-layout.c (tui_apply_current_layout): Add an assert.
> Andrew> * tui/tui.c (tui_enable): Move setting of tui_active earlier in
> Andrew> the function.
>
> Hi. Thanks for the patch.
>
> I really thought I had covered this scenario somehow, but I guess not!
> Oops, sorry about that. Maybe I was thinking that tui disable would
> destory the windows. Or maybe I planned to do that and then never did.
> I don't recall any more.
>
> Andrew> - if (win->window == nullptr)
> Andrew> - {
> Andrew> - PyErr_Format (PyExc_RuntimeError, _("TUI window is invalid."));
> Andrew> - return -1;
> Andrew> - }
> Andrew> -
> Andrew> - if (win->window == nullptr)
> Andrew> - {
> Andrew> - PyErr_Format (PyExc_TypeError, _("Cannot delete \"title\" attribute."));
> Andrew> - return -1;
> Andrew> - }
>
> This second 'if' has the same condition. It's actually a latent bug, as
> the code should read:
>
> if (newvalue == nullptr)
>
> ... and then the "if" should remain, rather than being deleted by this
> patch.
>
> I think the patch is ok with this tweak.
Thanks for pointing this out.
I span this fix out into its own commit and added a test for it.
Below is what I pushed.
Thanks,
Andrew
---
commit e0c23e11da18b615c382888da8e978f16428e81b
Author: Andrew Burgess <andrew.burgess@embecosm.com>
Date: Mon Feb 8 11:44:51 2021 +0000
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.
diff --git a/gdb/python/py-tui.c b/gdb/python/py-tui.c
index 6e9a1462ec5..73b73f33d4a 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/gdb.python/tui-window.exp b/gdb/testsuite/gdb.python/tui-window.exp
index 13e14be0654..8d86afb1449 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 88a1b06f12c..3bea78846ae 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")
next prev parent reply other threads:[~2021-02-08 11:58 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20201229170227.821-1-ssbssa.ref@yahoo.de>
2020-12-29 17:02 ` [PATCH 1/4] Fix wrong method name Hannes Domani
2020-12-29 17:02 ` [PATCH 2/4] Return true in TuiWindow.is_valid only if TUI is enabled Hannes Domani
2020-12-31 4:24 ` Simon Marchi
2021-01-15 16:48 ` Andrew Burgess
2021-01-15 17:22 ` Hannes Domani
2021-01-17 11:31 ` Andrew Burgess
2021-01-17 13:19 ` Hannes Domani
2021-01-18 10:30 ` Andrew Burgess
2021-01-18 11:29 ` Hannes Domani
2021-01-23 17:54 ` Andrew Burgess
2021-01-23 17:55 ` Andrew Burgess
2021-01-24 12:33 ` Hannes Domani
2021-02-06 19:38 ` Tom Tromey
2021-02-08 11:58 ` Andrew Burgess [this message]
2021-02-08 19:19 ` Tom Tromey
2021-01-18 17:19 ` Eli Zaretskii
2020-12-29 17:02 ` [PATCH 3/4] Add optional styled argument to gdb.execute Hannes Domani
2020-12-29 17:19 ` Eli Zaretskii
2020-12-31 4:28 ` Simon Marchi
2020-12-29 17:02 ` [PATCH 4/4] Fix raw-frame-arguments in combination with frame-filters Hannes Domani
2020-12-31 4:53 ` Simon Marchi
2020-12-31 14:01 ` Hannes Domani
2021-01-31 7:13 ` Joel Brobecker
2020-12-29 17:18 ` [PATCH 1/4] Fix wrong method name Eli Zaretskii
2020-12-29 17:39 ` Hannes Domani
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20210208115838.GF265215@embecosm.com \
--to=andrew.burgess@embecosm.com \
--cc=gdb-patches@sourceware.org \
--cc=ssbssa@yahoo.de \
--cc=tom@tromey.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).