gdb, remote: fix notify debug nullptr dereference

Message ID 20260504071636.1571615-3-markus.t.metzger@intel.com
State New
Headers
Series gdb, remote: fix notify debug nullptr dereference |

Commit Message

Metzger, Markus T May 4, 2026, 7:16 a.m. UTC
  In remote_target:push_stop_reply, notif debug prints an element that has
been moved.  Print the element at the destination, instead.
---
 gdb/remote.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
  

Comments

Simon Marchi May 4, 2026, 3:40 p.m. UTC | #1
On 5/4/26 3:16 AM, Markus Metzger wrote:
> In remote_target:push_stop_reply, notif debug prints an element that has
> been moved.  Print the element at the destination, instead.

So, there is a clang-tidy check for that, and indeed it finds it (and
more, but I'm just pasting the relevant one):

    $ clang-tidy  '-checks=bugprone-use-after-move' remote.c
    ...
    /home/smarchi/src/binutils-gdb/gdb/remote.c:8409:3: warning: 'new_event' used after it was moved [bugprone-use-after-move]
     8409 |                 new_event->ptid.to_string ().c_str (),
          |                 ^
    /home/smarchi/src/binutils-gdb/gdb/remote.c:8404:24: note: move occurred here
     8404 |   rs->stop_reply_queue.push_back (std::move (new_event));

I think we should set up a .clang-tidy file with the checks we care
about an run it in the CI, I'll look into that.

Approved-By: Simon Marchi <simon.marchi@efficios.com>

Simon
  

Patch

diff --git a/gdb/remote.c b/gdb/remote.c
index 1455838c2cf..735774903f3 100644
--- a/gdb/remote.c
+++ b/gdb/remote.c
@@ -8406,7 +8406,7 @@  remote_target::push_stop_reply (stop_reply_up new_event)
   if (notif_debug)
     gdb_printf (gdb_stdlog,
 		"notif: push 'Stop' %s to queue %d\n",
-		new_event->ptid.to_string ().c_str (),
+		rs->stop_reply_queue.back ()->ptid.to_string ().c_str (),
 		int (rs->stop_reply_queue.size ()));
 
   /* Mark the pending event queue only if async mode is currently enabled.