From: Andrew Burgess via Gdb-patches <gdb-patches@sourceware.org>
To: gdb-patches@sourceware.org
Cc: Andrew Burgess <aburgess@redhat.com>
Subject: [PATCH 1/2] gdb: fix possible nullptr dereference in a remote_debug_printf call
Date: Tue, 18 Jul 2023 15:31:45 +0100 [thread overview]
Message-ID: <5476235cc65b171f32663fa5e0af0a62342d1f63.1689690655.git.aburgess@redhat.com> (raw)
In-Reply-To: <cover.1689690655.git.aburgess@redhat.com>
While working on the next patch I triggered a segfault from within the
function remote_target::discard_pending_stop_replies. Turns out this
was caused by a cut&paste error introduced in this commit:
commit df5ad102009c41ab4dfadbb8cfb8c8b2a02a4f78
Date: Wed Dec 1 09:40:03 2021 -0500
gdb, gdbserver: detach fork child when detaching from fork parent
This commit adds a remote_debug_printf call that was copied from
earlier in the function, however, the new call wasn't updated to use
the appropriate local variable. The local variable that it is using
might be nullptr, in which case we trigger undefined behaviour, and
could crash, which is what I was seeing.
Fixed by updating to use the correct local variable.
---
gdb/remote.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/gdb/remote.c b/gdb/remote.c
index 7e3d6adfe4f..ff3d7e5cd32 100644
--- a/gdb/remote.c
+++ b/gdb/remote.c
@@ -7564,8 +7564,8 @@ remote_target::discard_pending_stop_replies (struct inferior *inf)
for (auto it = iter; it != rs->stop_reply_queue.end (); ++it)
remote_debug_printf
("discarding queued stop reply: ptid: %s, ws: %s\n",
- reply->ptid.to_string().c_str(),
- reply->ws.to_string ().c_str ());
+ (*it)->ptid.to_string().c_str(),
+ (*it)->ws.to_string ().c_str ());
rs->stop_reply_queue.erase (iter, rs->stop_reply_queue.end ());
}
--
2.25.4
next prev parent reply other threads:[~2023-07-18 14:32 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-07-18 14:31 [PATCH 0/2] Exit during detach Andrew Burgess via Gdb-patches
2023-07-18 14:31 ` Andrew Burgess via Gdb-patches [this message]
2023-07-19 15:01 ` [PATCH 1/2] gdb: fix possible nullptr dereference in a remote_debug_printf call Tom Tromey
2023-08-03 9:07 ` Andrew Burgess via Gdb-patches
2023-07-18 14:31 ` [PATCH 2/2] gdb: handle main thread exiting during detach Andrew Burgess via Gdb-patches
2023-07-18 14:40 ` Andrew Burgess via Gdb-patches
2023-08-03 9:50 ` [PATCHv2] " Andrew Burgess via Gdb-patches
2023-08-23 11:26 ` [PATCHv3] " Andrew Burgess via Gdb-patches
2023-09-29 13:57 ` [PATCHv4] " Andrew Burgess via Gdb-patches
2023-10-18 9:49 ` [PATCHv5] " Andrew Burgess
2023-10-25 21:40 ` Kevin Buettner
2023-10-26 17:26 ` 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=5476235cc65b171f32663fa5e0af0a62342d1f63.1689690655.git.aburgess@redhat.com \
--to=gdb-patches@sourceware.org \
--cc=aburgess@redhat.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