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 A85973858C52 for ; Wed, 20 Jul 2022 13:14:57 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org A85973858C52 Received: from mail-wm1-f72.google.com (mail-wm1-f72.google.com [209.85.128.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-321-Zx0ys4gjOGGDL0zs9JOMIA-1; Wed, 20 Jul 2022 09:14:55 -0400 X-MC-Unique: Zx0ys4gjOGGDL0zs9JOMIA-1 Received: by mail-wm1-f72.google.com with SMTP id v11-20020a1cf70b000000b003a318238826so774715wmh.2 for ; Wed, 20 Jul 2022 06:14:55 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=kxShuFCwt7kIB6S0g4M725Th5rcoinPTkJupN/qSQzA=; b=Cdl+yLCihZs0LBBFj0GMvU6O/GXcVdi2INYeM83Q8ftgYARCP/C9EoS2N2DbDVT79e KdlI4d7SmIWKQxmFyWnK41PA86zUVH0IKWjL8dJYY7rvSfnpu3AfAUnvcD8t7xGnq0ek cUbbtTnOvgOs/F4e1IbDBwFP3LKbjd4l2H07FTkArbHsLjfqFil2td7w4fHAWSOqxsuy nTDvCpxhPMT51aXS0k5UByIX13UKJhzEknNKucpqUeVJeUyzHU2rpeuimQ6VJFbT8FPl j2N7g1Ee31sKGt7VVVqH9bubDhg9cCx1f6ftFf3+OJjQ5ypLicYcyEt/SEkHBgSiVnVf 7jPA== X-Gm-Message-State: AJIora9QLzRf+LML4D6f1BbJIWU/xsoMmYNp9ktCWi4JJbUglwmYziwN W1fxP20jsCVhkH+GyIkAPPSZprQ69eQFVBPzRLXbnfMrGHk5kU3sUY679q8gpYKiOo4mtBOf804 hzMDJ7u9whcxl5JhGP35vkRLLwLpXssxs+PE+bAi0AaqC0eS4VtswtijO3ARUWdk5nDVyI8E50A == X-Received: by 2002:a1c:2b06:0:b0:3a2:f1ed:f470 with SMTP id r6-20020a1c2b06000000b003a2f1edf470mr3956814wmr.190.1658322894368; Wed, 20 Jul 2022 06:14:54 -0700 (PDT) X-Google-Smtp-Source: AGRyM1toaz2CsH9ZINyp7DR2FmtDwUFaO6dQwRVgN+ZCikkrQFRSKZfa4P/zexat4jSixDGJ7tOSbw== X-Received: by 2002:a1c:2b06:0:b0:3a2:f1ed:f470 with SMTP id r6-20020a1c2b06000000b003a2f1edf470mr3956792wmr.190.1658322894150; Wed, 20 Jul 2022 06:14:54 -0700 (PDT) Received: from localhost (15.72.115.87.dyn.plus.net. [87.115.72.15]) by smtp.gmail.com with ESMTPSA id v12-20020adfe28c000000b0021e2e1b17d9sm4800612wri.51.2022.07.20.06.14.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 Jul 2022 06:14:53 -0700 (PDT) From: Andrew Burgess To: gdb-patches@sourceware.org Cc: Andrew Burgess Subject: [PATCH 1/2] gdb: fix use of uninitialised gdb_printing_disassembler::m_in_comment Date: Wed, 20 Jul 2022 14:14:36 +0100 Message-Id: <7294738601aa52d1bba07129370bdc12724d9dc3.1658322626.git.aburgess@redhat.com> X-Mailer: git-send-email 2.25.4 In-Reply-To: References: <60eaedb1-8caf-1a52-0875-e3c5f5c8d8d4@simark.ca> MIME-Version: 1.0 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=-10.8 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_BARRACUDACENTRAL, RCVD_IN_DNSWL_LOW, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 20 Jul 2022 13:15:00 -0000 Simon pointed out that gdb_printing_disassembler::m_in_comment can be used uninitialised by the Python disassembler API code. This issue was spotted when GDB was built with the undefined behaviour sanitizer, and causes the gdb.python/py-disasm.exp test to fail like this: (gdb) PASS: gdb.python/py-disasm.exp: global_disassembler=GlobalPreInfoDisassembler: python add_global_disassembler(GlobalPreInfoDisassembler) disassemble main Dump of assembler code for function main: 0x0000555555555119 <+0>: push %rbp 0x000055555555511a <+1>: mov %rsp,%rbp 0x000055555555511d <+4>: nop /home/user/src/binutils-gdb/gdb/disasm.h:144:12: runtime error: load of value 118, which is not a valid value for type 'bool' The problem is that in disasmpy_builtin_disassemble we create a new instance of gdbpy_disassembler, which is a sub-class of gdb_printing_disassembler, however, the m_in_comment field is never initialised. This commit fixes the issue by providing a default initialisation value for m_in_comment in disasm.h. As we only ever disassemble a single instruction in disasmpy_builtin_disassemble then we don't need to worry about reseting m_in_comment back to false after the single instruction has been disassembled. With this commit the above issue is resolved and gdb.python/py-disasm.exp now passes. --- gdb/disasm.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gdb/disasm.h b/gdb/disasm.h index 2921d537e0a..09cb3921767 100644 --- a/gdb/disasm.h +++ b/gdb/disasm.h @@ -166,7 +166,7 @@ struct gdb_printing_disassembler : public gdb_disassemble_info uses styled output and emits a start of comment character. It is up to the code that uses this disassembler class to reset this flag back to false at a suitable time (e.g. at the end of every line). */ - bool m_in_comment; + bool m_in_comment = false; }; /* A basic disassembler that doesn't actually print anything. */ -- 2.25.4