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 4/5] [gdb/remote] Harden comma separator in parse_tracepoint_definition
Date: Thu, 12 Nov 2026 09:41:15 -0800	[thread overview]
Message-ID: <896877f35cba68aba9475587591452281620f67e.1794430701.git.keiths@redhat.com> (raw)
In-Reply-To: <cover.1794430701.git.keiths@redhat.com>

The optional :X<len>,<hex> condition field in a tracepoint definition
skipped past a comma without checking that the separator was present.
Convert that site to the shared separator helper and add unit tests
for missing-comma inputs.
---
 gdb/tracepoint.c                     |  2 +-
 gdb/unittests/tracepoint-selftests.c | 21 +++++++++++++++++++--
 2 files changed, 20 insertions(+), 3 deletions(-)

diff --git a/gdb/tracepoint.c b/gdb/tracepoint.c
index 65e17517a77..285fbd18c8c 100644
--- a/gdb/tracepoint.c
+++ b/gdb/tracepoint.c
@@ -3477,7 +3477,7 @@ parse_tracepoint_definition (const char *line, struct uploaded_tp **utpp)
 	    {
 	      p++;
 	      p = unpack_varlen_hex (p, &xlen);
-	      p++;  /* skip a comma */
+	      p = require (p, ',');
 	      cond = make_unique_xstrndup (p, 2 * xlen);
 	      p += 2 * xlen;
 	    }
diff --git a/gdb/unittests/tracepoint-selftests.c b/gdb/unittests/tracepoint-selftests.c
index 768e1a9e83b..f6d5317e9d2 100644
--- a/gdb/unittests/tracepoint-selftests.c
+++ b/gdb/unittests/tracepoint-selftests.c
@@ -201,8 +201,9 @@ expect_bad_tracepoint_definition (const char *line)
 			 [&] () { free_uploaded_tps (&utps); });
 }
 
-/* Test parse_tracepoint_definition, including missing-colon rejects and
-   enable-flag rejects.  */
+/* Test parse_tracepoint_definition, including missing-colon rejects,
+   enable-flag rejects, missing-comma rejects for the 'X' condition
+   field, and the 'Z' branch stale-tail cases.  */
 
 static void
 test_parse_tracepoint_definition ()
@@ -240,6 +241,22 @@ test_parse_tracepoint_definition ()
   expect_bad_tracepoint_definition ("T1:0:E");
   expect_bad_tracepoint_definition ("T1:0:E:0");
 
+  /* Well-formed T definition with an agent-expression condition.
+     Encoded form is ...:X<len>,<hex>.  */
+  {
+    const char *good = "T1:0:E:0:0:X1,00";
+
+    parse_tracepoint_definition (good, &utps);
+    SELF_CHECK (utps != nullptr);
+    SELF_CHECK (utps->cond != nullptr
+		&& streq (utps->cond.get (), "00"));
+    free_uploaded_tps (&utps);
+  }
+
+  /* Missing comma after the X length.  */
+  expect_bad_tracepoint_definition ("T1:0:E:0:0:X1");
+  expect_bad_tracepoint_definition ("T1:0:E:0:0:X1:00");
+
   /* Well-formed Z definition: at-string hex-encodes "foo".
      Encoded form is Z<num>:<addr>:<srctype>:<start>:<len>:<hex>.  */
   {
-- 
2.56.0


  parent reply	other threads:[~2026-11-12 17:43 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 ` [PATCH 3/5] [gdb/remote] Harden parse_static_tracepoint_marker_definition Keith Seitz
2026-11-12 17:41 ` Keith Seitz [this message]
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=896877f35cba68aba9475587591452281620f67e.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