From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca (simark.ca [158.69.221.121]) by sourceware.org (Postfix) with ESMTPS id 682003858D37 for ; Wed, 20 Jul 2022 14:21:49 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 682003858D37 Received: from [10.0.0.11] (192-222-157-6.qc.cable.ebox.net [192.222.157.6]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by simark.ca (Postfix) with ESMTPSA id 19E021E21F; Wed, 20 Jul 2022 10:21:49 -0400 (EDT) Message-ID: <58d06f91-11ee-c52b-d64d-ba6b80a245fb@simark.ca> Date: Wed, 20 Jul 2022 10:21:48 -0400 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.11.0 Subject: Re: [PATCH 1/2] gdb: fix use of uninitialised gdb_printing_disassembler::m_in_comment Content-Language: en-US To: Andrew Burgess , gdb-patches@sourceware.org References: <60eaedb1-8caf-1a52-0875-e3c5f5c8d8d4@simark.ca> <7294738601aa52d1bba07129370bdc12724d9dc3.1658322626.git.aburgess@redhat.com> From: Simon Marchi In-Reply-To: <7294738601aa52d1bba07129370bdc12724d9dc3.1658322626.git.aburgess@redhat.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-11.2 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, NICE_REPLY_A, SPF_HELO_PASS, SPF_PASS, 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 14:21:50 -0000 On 2022-07-20 09:14, Andrew Burgess via Gdb-patches wrote: > 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. */ Thanks, LGTM. Simon