public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Simon Marchi <simark@simark.ca>
To: Andrew Burgess <aburgess@redhat.com>, gdb-patches@sourceware.org
Subject: Re: [PATCH 1/2] gdb: fix use of uninitialised gdb_printing_disassembler::m_in_comment
Date: Wed, 20 Jul 2022 10:21:48 -0400	[thread overview]
Message-ID: <58d06f91-11ee-c52b-d64d-ba6b80a245fb@simark.ca> (raw)
In-Reply-To: <7294738601aa52d1bba07129370bdc12724d9dc3.1658322626.git.aburgess@redhat.com>



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

  reply	other threads:[~2022-07-20 14:21 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-06-17 10:36 [PATCH 0/2] Use libopcodes disassembler styling with GDB Andrew Burgess
2022-06-17 10:36 ` [PATCH 1/2] gdb: have gdb_disassemble_info carry 'this' in its stream pointer Andrew Burgess
2022-06-17 10:36 ` [PATCH 2/2] gdb: add support for disassembler styling using libopcodes Andrew Burgess
2022-06-17 11:16   ` Eli Zaretskii
2022-06-30 12:22     ` Andrew Burgess
2022-06-30 13:46       ` Eli Zaretskii
2022-07-04 10:15         ` Andrew Burgess
2022-07-20  2:09   ` Simon Marchi
2022-07-20 13:14     ` [PATCH 0/2] Fix some undefined haviour bugs in Python disassembler API Andrew Burgess
2022-07-20 13:14       ` [PATCH 1/2] gdb: fix use of uninitialised gdb_printing_disassembler::m_in_comment Andrew Burgess
2022-07-20 14:21         ` Simon Marchi [this message]
2022-07-20 13:14       ` [PATCH 2/2] gdb/python: fix invalid use disassemble_info::stream Andrew Burgess
2022-07-25 18:27       ` [PATCH 0/2] Fix some undefined haviour bugs in Python disassembler API Andrew Burgess
2022-07-04 10:17 ` [PATCH 0/2] Use libopcodes disassembler styling with GDB Andrew Burgess
2022-07-11 14:18   ` Andrew Burgess

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=58d06f91-11ee-c52b-d64d-ba6b80a245fb@simark.ca \
    --to=simark@simark.ca \
    --cc=aburgess@redhat.com \
    --cc=gdb-patches@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).