Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Keith Seitz <keiths@redhat.com>
To: gdb-patches@sourceware.org
Subject: [PATCH 3/5] [gdb/remote] Harden parse_static_tracepoint_marker_definition
Date: Thu, 12 Nov 2026 09:41:14 -0800	[thread overview]
Message-ID: <e3a7ffcaadaff1da9f3d889e769ba099a18b29b2.1794430701.git.keiths@redhat.com> (raw)
In-Reply-To: <cover.1794430701.git.keiths@redhat.com>

Similar to parse_tsv_definition and parse_tracepoint_definition,
parse_static_tracepoint_marker_definition skipped field separators
without checking whether the skipped character is really a colon.

Convert it to the shared separator helpers and add unit tests for
missing-colon inputs.
---
 gdb/tracepoint.c                     | 17 +++++++++--------
 gdb/unittests/tracepoint-selftests.c | 17 +++++++++++++++++
 2 files changed, 26 insertions(+), 8 deletions(-)

diff --git a/gdb/tracepoint.c b/gdb/tracepoint.c
index 7a3339617ef..65e17517a77 100644
--- a/gdb/tracepoint.c
+++ b/gdb/tracepoint.c
@@ -3577,21 +3577,22 @@ parse_static_tracepoint_marker_definition (const char *line, const char **pp,
   const char *p, *endp;
   ULONGEST addr;
 
+  auto require = [&] (const char *q, char sep = ':')
+    {
+      return trace_definition_require_char (q, sep, "marker", line);
+    };
+
   p = line;
   p = unpack_varlen_hex (p, &addr);
-  p++;  /* skip a colon */
+  p = require (p);
 
   marker->gdbarch = current_inferior ()->arch ();
   marker->address = (CORE_ADDR) addr;
 
+  const char *id_start = p;
   endp = strchr (p, ':');
-  if (endp == NULL)
-    error (_("bad marker definition: %s"), line);
-
-  marker->str_id = hex2str (p, (endp - p) / 2);
-
-  p = endp;
-  p++; /* skip a colon */
+  p = require (endp);
+  marker->str_id = hex2str (id_start, (endp - id_start) / 2);
 
   /* This definition may be followed by another one, separated by a comma.  */
   int hex_len;
diff --git a/gdb/unittests/tracepoint-selftests.c b/gdb/unittests/tracepoint-selftests.c
index ded37f390e6..768e1a9e83b 100644
--- a/gdb/unittests/tracepoint-selftests.c
+++ b/gdb/unittests/tracepoint-selftests.c
@@ -58,6 +58,20 @@ expect_bad_definition (Parse parse)
   expect_bad_definition (parse, [] () {});
 }
 
+/* Assert that LINE is rejected as a malformed static tracepoint marker
+   definition.  */
+
+static void
+expect_bad_static_tracepoint_marker_definition (const char *line)
+{
+  static_tracepoint_marker marker;
+
+  expect_bad_definition ([&] ()
+    {
+      parse_static_tracepoint_marker_definition (line, nullptr, &marker);
+    });
+}
+
 static void
 test_parse_static_tracepoint_marker_definition ()
 {
@@ -90,6 +104,9 @@ test_parse_static_tracepoint_marker_definition ()
   SELF_CHECK (marker.str_id == "marker3");
   SELF_CHECK (marker.extra == "morestuff");
   SELF_CHECK (end == def + strlen (def));
+
+  expect_bad_static_tracepoint_marker_definition ("1234");
+  expect_bad_static_tracepoint_marker_definition ("1234:6d61726b657231");
 }
 
 /* Free UTSVP, including each node's name.  */
-- 
2.56.0


  parent reply	other threads:[~2026-11-12 17:42 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-12 17:41 [PATCH 0/5] tracepoint.c hardening against missing separators Keith Seitz
2026-11-12 17:41 ` [PATCH 1/5] [gdb/remote] Fix stack overflow in parse_tsv_definition Keith Seitz
2026-11-24 12:07   ` Andrew Burgess
2026-11-12 17:41 ` [PATCH 2/5] [gdb/remote] Fix stack overflow in parse_tracepoint_definition Keith Seitz
2026-11-24 14:45   ` Andrew Burgess
2026-11-24 17:12     ` Andrew Burgess
2026-11-24 19:28     ` Keith Seitz
2026-11-12 17:41 ` Keith Seitz [this message]
2026-11-12 17:41 ` [PATCH 4/5] [gdb/remote] Harden comma separator " Keith Seitz
2026-11-12 17:41 ` [PATCH 5/5] [gdb/remote] Harden parse_tracepoint_status Keith Seitz
2026-11-24 17:14 ` [PATCH 0/5] tracepoint.c hardening against missing separators Andrew Burgess
2026-11-25 17:38   ` Keith Seitz

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=e3a7ffcaadaff1da9f3d889e769ba099a18b29b2.1794430701.git.keiths@redhat.com \
    --to=keiths@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