From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTPS id 9AAF43858D32 for ; Wed, 5 Jul 2023 00:08:35 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 9AAF43858D32 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1688515715; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=gz24XIJJBhvQARRfAVi6v3JdTdRkSAdpfs0jPERiwEc=; b=ayFRds9EGRQaDcUuN50GASybeqBhbjo0HEF1yU4S5mY0elSwlt6kW7KjT1sjpQELaWBovy RZE9uHKwYhl5mItlpF78x4uYTu2Z0+64cJA8SQVCBYBoWVMFkKZmj31bY126oO5YJ1MMoE QAJ5fjVWLnRYLL7aOPaRCxodtwY+Vz0= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-119-5WXjbARlOW2ZDGTT6YTP8w-1; Tue, 04 Jul 2023 20:08:33 -0400 X-MC-Unique: 5WXjbARlOW2ZDGTT6YTP8w-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 78DA785A58A for ; Wed, 5 Jul 2023 00:08:33 +0000 (UTC) Received: from fedora.redhat.com (unknown [10.22.32.55]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1B8DE40C2063; Wed, 5 Jul 2023 00:08:33 +0000 (UTC) From: Aaron Merey To: gdb-patches@sourceware.org Cc: Aaron Merey Subject: [PATCH] gdb/cp-namespace.c: Fix assert failure caused by malformed user input Date: Tue, 4 Jul 2023 20:08:29 -0400 Message-ID: <20230705000829.203211-1-amerey@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.1 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="US-ASCII"; x-default=true X-Spam-Status: No, score=-11.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_NONE,TXREP,T_SCC_BODY_TEXT_LINE,WEIRD_PORT autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: When debugging C++ programs, it is possible to trigger a spurious assert failure when attempting to set a breakpoint on a malformed symbol name. Names of the form 'A>::B' trigger this assert failure in cp_lookup_bare_symbol: $ gdb gdb [...] (gdb) br test>::assert Function "test>::assert" not defined. Make breakpoint pending on future shared library load? (y or [n]) y Breakpoint 1 (test>::assert) pending. (gdb) start [...] cp-namespace.c:181: internal-error: cp_lookup_bare_symbol: Assertion `strstr (name, "::") == NULL' failed. A problem internal to GDB has been detected, further debugging may prove unreliable. ----- Backtrace ----- 0x5217e2 gdb_internal_backtrace_1 /home/amerey/binutils-gdb/gdb/bt-utils.c:122 0x521885 _Z22gdb_internal_backtracev /home/amerey/binutils-gdb/gdb/bt-utils.c:168 0xaf8303 internal_vproblem /home/amerey/binutils-gdb/gdb/utils.c:396 0xaf86be _Z15internal_verrorPKciS0_P13__va_list_tag /home/amerey/binutils-gdb/gdb/utils.c:476 0xccdb3f _Z18internal_error_locPKciS0_z /home/amerey/binutils-gdb/gdbsupport/errors.cc:58 0x5dded9 cp_lookup_bare_symbol /home/amerey/binutils-gdb/gdb/cp-namespace.c:181 0x5de39d cp_lookup_symbol_in_namespace /home/amerey/binutils-gdb/gdb/cp-namespace.c:328 [...] Currently this assert is skipped if the symbol name contains '<' or '('. Fix this spurious failure by also skipping the assert when the symbol name contains '>'. Regression tested on F38 x86_64. --- gdb/cp-namespace.c | 5 +++-- gdb/testsuite/gdb.cp/namespace.exp | 4 ++++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/gdb/cp-namespace.c b/gdb/cp-namespace.c index 14d807694b7..f36bec5b1f8 100644 --- a/gdb/cp-namespace.c +++ b/gdb/cp-namespace.c @@ -177,8 +177,9 @@ cp_lookup_bare_symbol (const struct language_defn *langdef, /* Note: We can't do a simple assert for ':' not being in NAME because ':' may be in the args of a template spec. This isn't intended to be a complete test, just cheap and documentary. */ - if (strchr (name, '<') == NULL && strchr (name, '(') == NULL) - gdb_assert (strstr (name, "::") == NULL); + if (strchr (name, '<') == nullptr && strchr (name, '>') == nullptr + && strchr (name, '(') == nullptr) + gdb_assert (strstr (name, "::") == nullptr); sym = lookup_symbol_in_static_block (name, block, domain); if (sym.symbol != NULL) diff --git a/gdb/testsuite/gdb.cp/namespace.exp b/gdb/testsuite/gdb.cp/namespace.exp index e364816fcb7..359b85ac393 100644 --- a/gdb/testsuite/gdb.cp/namespace.exp +++ b/gdb/testsuite/gdb.cp/namespace.exp @@ -250,3 +250,7 @@ gdb_test "print AAA::ALPHA" "\\$\[0-9\].* = AAA::ALPHA" # Regression tests for PR 9496. gdb_test "whatis ::C::CClass::NestedClass" "type = C::CClass::NestedClass" gdb_test "whatis ::C::CClass::NestedClass *" "type = C::CClass::NestedClass \\*" + +# Break on a function with a malformed name. +gdb_test "break DNE>::DNE" "" "br malformed" \ + "Make breakpoint pending on future shared library load?.*" "y" -- 2.41.0