From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id UVsPMbD69WrXfQYAWB0awg (envelope-from ) for ; Thu, 12 Nov 2026 12:43:12 -0500 Authentication-Results: simark.ca; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=WxtQBqao; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id C533D1E0BC; Thu, 12 Nov 2026 12:43:12 -0500 (EST) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-3.1 required=5.0 tests=ARC_SIGNED,ARC_VALID,BAYES_00, DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED,RCVD_IN_SBL_CSS autolearn=ham autolearn_force=no version=4.0.1 Received: from vm01.sourceware.org (vm01.sourceware.org [IPv6:2620:52:6:3111::32]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange x25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPS id 4FFA21E087 for ; Thu, 12 Nov 2026 12:43:12 -0500 (EST) Received: from vm01.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 271EC4BA23D7 for ; Thu, 12 Nov 2026 17:43:11 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 271EC4BA23D7 Authentication-Results: sourceware.org; dkim=pass (1024-bit key, unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=WxtQBqao Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTP id C24A04BA23C1 for ; Thu, 12 Nov 2026 17:41:27 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org C24A04BA23C1 Authentication-Results: sourceware.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org C24A04BA23C1 Authentication-Results: sourceware.org; arc=none smtp.remote-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1794505287; cv=none; b=GCwsa6IqrG+stEGEZ0f3Am7D8JWRvybNG25Kb4QLots1xcAsZ8dHyM4iD07PUW2nG0LwWoyp2Q6ub46tC4urur8CqPOmblNh0reoqFzFz3cVypH+JxvSI7oHk9i6U2auvx3tAD/xQFNy7nLPVXG7aSo4SuQ5UTPdTFKIDC/4FMk= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1794505287; c=relaxed/simple; bh=aE6CrNmsSWI4Qo0lkML8WrDilit2z+MikThwFnczwT4=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=Y4l7LkzVtxpQ+QFMQnPXDAtj63Ijd9u84iFH1C+tpUOmzP+2w4YCBlDfFMYUI4lmTIGWPPIhlBGYiKByF+M4rDIOQVEbjsxqHAe4tu26ppd/HxIZ/eEhNk3cbI71GL2zVI3yeMtXZ8NOMaM14a0sh5r44+z4WqIo9uXpOYrr0Kc= ARC-Authentication-Results: i=1; sourceware.org; dkim=pass (1024-bit key, unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=WxtQBqao DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org C24A04BA23C1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1794505287; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=M18gv66SqlkCSX+0S8RAbqqfKYxrS5wOg1Z/R4iQ8qg=; b=WxtQBqaoH6kLDLqqUbi78UwkhhkesReu2qJaIniFU77htDIcVGzh6kYMCSImR5o3BXr7nA kQdxbAS5zwGirWHjwZZmm/E/v9SeRnJkSOQiIzMTsk4ifGWtv7uikBHrZcRjdfXlb8Vucz LwmwwoWr86V6tFCihim5tjCNHlRrVFs= Received: from mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-321-BzOCCjVWNhSgFsmzXh4o9A-1; Thu, 12 Nov 2026 12:41:25 -0500 X-MC-Unique: BzOCCjVWNhSgFsmzXh4o9A-1 X-Mimecast-MFC-AGG-ID: BzOCCjVWNhSgFsmzXh4o9A_1794505285 Received: from mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.12]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 0C09A195605F for ; Thu, 12 Nov 2026 17:41:25 +0000 (UTC) Received: from keiths-thinkpadp1gen7.redhat.corp (headnet04.pony-001.prod.iad2.dc.redhat.com [10.2.32.116]) by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 7035C1956087 for ; Thu, 12 Nov 2026 17:41:24 +0000 (UTC) From: Keith Seitz To: gdb-patches@sourceware.org Subject: [PATCH 5/5] [gdb/remote] Harden parse_tracepoint_status Date: Thu, 12 Nov 2026 09:41:16 -0800 Message-ID: <209e4c9eecc4bec68a3b73a05bdc34647da59e40.1794430701.git.keiths@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.12 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: ku5tpG3f7y1EDBaTT4Uot-4CeKgajSFQmj0P0lpJcnY_1794505285 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: 8bit content-type: text/plain; charset="US-ASCII"; x-default=true X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gdb-patches-bounces~public-inbox=simark.ca@sourceware.org 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 :. */ + +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