From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1726) id AFE5A38582AE; Mon, 25 Jul 2022 18:26:57 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org AFE5A38582AE Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Andrew Burgess To: gdb-cvs@sourceware.org Subject: [binutils-gdb] gdb: fix use of uninitialised gdb_printing_disassembler::m_in_comment X-Act-Checkin: binutils-gdb X-Git-Author: Andrew Burgess X-Git-Refname: refs/heads/master X-Git-Oldrev: e4146092c3f147b8c395febc771edd7de23f724d X-Git-Newrev: 554128418b4f1328bb956d5926f24bfd56fd45ea Message-Id: <20220725182657.AFE5A38582AE@sourceware.org> Date: Mon, 25 Jul 2022 18:26:57 +0000 (GMT) X-BeenThere: gdb-cvs@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 25 Jul 2022 18:26:57 -0000 https://sourceware.org/git/gitweb.cgi?p=3Dbinutils-gdb.git;h=3D554128418b4f= 1328bb956d5926f24bfd56fd45ea commit 554128418b4f1328bb956d5926f24bfd56fd45ea Author: Andrew Burgess Date: Wed Jul 20 13:00:40 2022 +0100 gdb: fix use of uninitialised gdb_printing_disassembler::m_in_comment =20 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: =20 (gdb) PASS: gdb.python/py-disasm.exp: global_disassembler=3DGlobalPre= InfoDisassembler: 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' =20 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. =20 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. =20 With this commit the above issue is resolved and gdb.python/py-disasm.exp now passes. Diff: --- 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 @@ private: 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 =3D false; }; =20 /* A basic disassembler that doesn't actually print anything. */