public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: "H.J. Lu" <hjl.tools@gmail.com>
To: Roland McGrath <mcgrathr@google.com>
Cc: "binutils@sourceware.org" <binutils@sourceware.org>,
	GDB <gdb-patches@sourceware.org>,
		Bradley Nelson <bradnelson@google.com>
Subject: Re: [PATCH] Fix buffer underrun in i386-dis.c.
Date: Thu, 09 Jan 2014 18:31:00 -0000	[thread overview]
Message-ID: <CAMe9rOrf6V5g5DL7-7McsLL=L+F3AkUjZj=b-WPOGKEmf+OV0w@mail.gmail.com> (raw)
In-Reply-To: <CAB=4xhooGrDed7eSXbPOYZjx57-HOQKCQq9wwEphWAgL0=Q8Hg@mail.gmail.com>

On Thu, Jan 9, 2014 at 10:26 AM, Roland McGrath <mcgrathr@google.com> wrote:
> When disassembling any instruction without a REX prefix, the print_insn
> function touches all_prefixes[-1].  This is usually harmless in most
> builds, because the word preceding all_prefixes will probably be the
> last_seg_prefix variable and it was usually zero already.  But in some
> kinds of builds, all buffer underruns are caught and cause a crash.
>
> AFAICT the obvious local workaround is in fact the proper fix.  In the
> similar cases nearby, there is a PREFIX_FOO bit in the "prefixes" bitmask
> that guards use of last_foo_prefix.  But there is no such bit for the REX
> prefixes.  We could test "rex != 0" instead, I suppose.
>
> OK for trunk and binutils-2.24 branch and gdb-7.7 branch?

OK for trunk and binutils-2.24 branch.

Thanks.

>
> Thanks,
> Roland
>
>
> opcodes/
> 2014-01-09  Bradley Nelson  <bradnelson@google.com>
>             Roland McGrath  <mcgrathr@google.com>
>
>         * i386-dis.c (print_insn): Do not touch all_prefixes[-1] when
>         last_rex_prefix is -1.
>
> --- a/opcodes/i386-dis.c
> +++ b/opcodes/i386-dis.c
> @@ -12645,7 +12645,7 @@ print_insn (bfd_vma pc, disassemble_info *info)
>      }
>
>    /* Check if the REX prefix is used.  */
> -  if (rex_ignored == 0 && (rex ^ rex_used) == 0)
> +  if (rex_ignored == 0 && (rex ^ rex_used) == 0 && last_rex_prefix >= 0)
>      all_prefixes[last_rex_prefix] = 0;
>
>    /* Check if the SEG prefix is used.  */



-- 
H.J.

  reply	other threads:[~2014-01-09 18:31 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-01-09 18:26 Roland McGrath
2014-01-09 18:31 ` H.J. Lu [this message]
2014-01-09 19:03   ` Pedro Alves
2014-01-09 19:28     ` Roland McGrath

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='CAMe9rOrf6V5g5DL7-7McsLL=L+F3AkUjZj=b-WPOGKEmf+OV0w@mail.gmail.com' \
    --to=hjl.tools@gmail.com \
    --cc=binutils@sourceware.org \
    --cc=bradnelson@google.com \
    --cc=gdb-patches@sourceware.org \
    --cc=mcgrathr@google.com \
    /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).