From: Andrew Burgess <andrew.burgess@embecosm.com>
To: gdb-patches@sourceware.org
Subject: [PUSHED] gdb/python: Avoid use after free in py-tui.c
Date: Fri, 5 Jun 2020 19:23:37 +0100 [thread overview]
Message-ID: <20200605182337.981585-1-andrew.burgess@embecosm.com> (raw)
When setting the window title of a tui frame we do this:
gdb::unique_xmalloc_ptr<char> value
= python_string_to_host_string (<python-object>);
...
win->window->title = value.get ();
The problem here is that 'get ()' only borrows the pointer from value,
when value goes out of scope the pointer will be freed. As a result,
the tui frame will be left with a pointer to undefined memory
contents.
Instead we should be using 'value.release ()' to take ownership of the
pointer from value.
gdb/ChangeLog:
* python/py-tui.c (gdbpy_tui_set_title): Use release, not get, to
avoid use after free.
---
gdb/ChangeLog | 5 +++++
gdb/python/py-tui.c | 2 +-
2 files changed, 6 insertions(+), 1 deletion(-)
diff --git a/gdb/python/py-tui.c b/gdb/python/py-tui.c
index ca88f85eb9f..f2c03395a0b 100644
--- a/gdb/python/py-tui.c
+++ b/gdb/python/py-tui.c
@@ -433,7 +433,7 @@ gdbpy_tui_set_title (PyObject *self, PyObject *newvalue, void *closure)
if (value == nullptr)
return -1;
- win->window->title = value.get ();
+ win->window->title = value.release ();
return 0;
}
--
2.25.4
next reply other threads:[~2020-06-05 18:23 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-06-05 18:23 Andrew Burgess [this message]
2020-06-05 18:26 ` Christian Biesinger
2020-06-05 18:37 ` Tom Tromey
2020-06-05 20:14 ` Andrew Burgess
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=20200605182337.981585-1-andrew.burgess@embecosm.com \
--to=andrew.burgess@embecosm.com \
--cc=gdb-patches@sourceware.org \
/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