Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Andrew Burgess <aburgess@redhat.com>
To: gdb-patches@sourceware.org
Cc: Andrew Burgess <aburgess@redhat.com>
Subject: [PATCH 1/2] gdbserver: move local variable declarations inline in cmd_qtstatus
Date: Mon, 23 Nov 2026 22:46:08 +0000	[thread overview]
Message-ID: <be577ce681d984e62519779d7daf5d6d2870fc69.1795473840.git.aburgess@redhat.com> (raw)
In-Reply-To: <cover.1795473839.git.aburgess@redhat.com>

Refactor cmd_qtstatus (gdbserver/tracepoint.cc) moving the local
variable declarations inline.  This is just a refactor, there should be
no user visible changes after this commit.
---
 gdbserver/tracepoint.cc | 29 ++++++++++-------------------
 1 file changed, 10 insertions(+), 19 deletions(-)

diff --git a/gdbserver/tracepoint.cc b/gdbserver/tracepoint.cc
index 6f657257ee8..bfe1ecc7db6 100644
--- a/gdbserver/tracepoint.cc
+++ b/gdbserver/tracepoint.cc
@@ -3375,27 +3375,22 @@ cmd_qtframe (char *own_buf)
 static void
 cmd_qtstatus (char *packet)
 {
-  char *stop_reason_rsp = NULL;
-  char *buf1, *buf2, *buf3;
-  const char *str;
-  int slen;
-
   /* Translate the plain text of the notes back into hex for
      transmission.  */
 
-  str = (tracing_user_name ? tracing_user_name : "");
-  slen = strlen (str);
-  buf1 = (char *) alloca (slen * 2 + 1);
+  const char *str = (tracing_user_name ? tracing_user_name : "");
+  int slen = strlen (str);
+  char *buf1 = (char *) alloca (slen * 2 + 1);
   bin2hex ((gdb_byte *) str, buf1, slen);
 
   str = (tracing_notes ? tracing_notes : "");
   slen = strlen (str);
-  buf2 = (char *) alloca (slen * 2 + 1);
+  char *buf2 = (char *) alloca (slen * 2 + 1);
   bin2hex ((gdb_byte *) str, buf2, slen);
 
   str = (tracing_stop_note ? tracing_stop_note : "");
   slen = strlen (str);
-  buf3 = (char *) alloca (slen * 2 + 1);
+  char *buf3 = (char *) alloca (slen * 2 + 1);
   bin2hex ((gdb_byte *) str, buf3, slen);
 
   trace_debug ("Returning trace status as %d, stop reason %s",
@@ -3408,22 +3403,18 @@ cmd_qtstatus (char *packet)
       upload_fast_traceframes ();
 
       target_unpause_all (true);
-   }
+    }
 
-  stop_reason_rsp = (char *) tracing_stop_reason;
+  char *stop_reason_rsp = (char *) tracing_stop_reason;
 
   /* The user visible error string in terror needs to be hex encoded.
      We leave it as plain string in `tracing_stop_reason' to ease
      debugging.  */
   if (startswith (stop_reason_rsp, "terror:"))
     {
-      const char *result_name;
-      int hexstr_len;
-      char *p;
-
-      result_name = stop_reason_rsp + strlen ("terror:");
-      hexstr_len = strlen (result_name) * 2;
-      p = stop_reason_rsp
+      const char *result_name = stop_reason_rsp + strlen ("terror:");
+      size_t hexstr_len = strlen (result_name) * 2;
+      char *p = stop_reason_rsp
 	= (char *) alloca (strlen ("terror:") + hexstr_len + 1);
       strcpy (p, "terror:");
       p += strlen (p);
-- 
2.56.1


  reply	other threads:[~2026-11-23 22:46 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-23 22:46 [PATCH 0/2] gdbserver: fix potential buffer overflow in qTStatus Andrew Burgess
2026-11-23 22:46 ` Andrew Burgess [this message]
2026-11-23 22:46 ` [PATCH 2/2] gdbserver: fix buffer overflow in cmd_qtstatus 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=be577ce681d984e62519779d7daf5d6d2870fc69.1795473840.git.aburgess@redhat.com \
    --to=aburgess@redhat.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