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 5/5] [gdb/remote] Harden parse_tracepoint_status
Date: Thu, 12 Nov 2026 09:41:16 -0800	[thread overview]
Message-ID: <209e4c9eecc4bec68a3b73a05bdc34647da59e40.1794430701.git.keiths@redhat.com> (raw)
In-Reply-To: <cover.1794430701.git.keiths@redhat.com>

parse_tracepoint_status skipped the colon between hit count and
traceframe usage without checking that the separator was present.
Convert it to the shared separator helper and add unit tests.
---
 gdb/tracepoint.c                     | 10 +++++-
 gdb/unittests/tracepoint-selftests.c | 48 ++++++++++++++++++++++++++++
 2 files changed, 57 insertions(+), 1 deletion(-)

diff --git a/gdb/tracepoint.c b/gdb/tracepoint.c
index 285fbd18c8c..d1053174eb4 100644
--- a/gdb/tracepoint.c
+++ b/gdb/tracepoint.c
@@ -3405,13 +3405,21 @@ parse_tracepoint_status (const char *p, tracepoint *tp,
 			 struct uploaded_tp *utp)
 {
   ULONGEST uval;
+  const char *line = p;
+
+  auto require = [&] (const char *q, char sep = ':')
+    {
+      return trace_definition_require_char (q, sep, "tracepoint status",
+					    line);
+    };
 
   p = unpack_varlen_hex (p, &uval);
   if (tp)
     tp->hit_count += uval;
   else
     utp->hit_count += uval;
-  p = unpack_varlen_hex (p + 1, &uval);
+  p = require (p);
+  p = unpack_varlen_hex (p, &uval);
   if (tp)
     tp->traceframe_usage += uval;
   else
diff --git a/gdb/unittests/tracepoint-selftests.c b/gdb/unittests/tracepoint-selftests.c
index f6d5317e9d2..479288b0bef 100644
--- a/gdb/unittests/tracepoint-selftests.c
+++ b/gdb/unittests/tracepoint-selftests.c
@@ -292,6 +292,51 @@ test_parse_tracepoint_definition ()
   }
 }
 
+/* Assert that LINE is rejected as a malformed tracepoint status.  */
+
+static void
+expect_bad_tracepoint_status (const char *line)
+{
+  uploaded_tp utp;
+
+  expect_bad_definition ([&] ()
+    {
+      parse_tracepoint_status (line, nullptr, &utp);
+    });
+}
+
+/* Test parse_tracepoint_status, including missing-colon rejects.
+   Status form is <hits>:<usage>.  */
+
+static void
+test_parse_tracepoint_status ()
+{
+  /* Well-formed status.  */
+  {
+    uploaded_tp utp;
+
+    parse_tracepoint_status ("5:a", nullptr, &utp);
+    SELF_CHECK (utp.hit_count == 5);
+    SELF_CHECK (utp.traceframe_usage == 0xa);
+  }
+
+  /* Also reachable via a V tracepoint definition piece.  */
+  {
+    uploaded_tp *utps = nullptr;
+
+    parse_tracepoint_definition ("V1:0:5:a", &utps);
+    SELF_CHECK (utps != nullptr);
+    SELF_CHECK (utps->hit_count == 5);
+    SELF_CHECK (utps->traceframe_usage == 0xa);
+    free_uploaded_tps (&utps);
+  }
+
+  expect_bad_tracepoint_status ("5");
+  expect_bad_tracepoint_status ("5a");
+  expect_bad_tracepoint_definition ("V1:0:5");
+  expect_bad_tracepoint_definition ("V1:0:5a");
+}
+
 } /* namespace tracepoint_tests */
 } /* namespace selftests */
 
@@ -306,4 +351,7 @@ INIT_GDB_FILE (tracepoint_selftests)
   selftests::register_test
     ("parse_tracepoint_definition",
      selftests::tracepoint_tests::test_parse_tracepoint_definition);
+  selftests::register_test
+    ("parse_tracepoint_status",
+     selftests::tracepoint_tests::test_parse_tracepoint_status);
 }
-- 
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 ` [PATCH 4/5] [gdb/remote] Harden comma separator in parse_tracepoint_definition Keith Seitz
2026-11-12 17:41 ` Keith Seitz [this message]
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=209e4c9eecc4bec68a3b73a05bdc34647da59e40.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