public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] Fix buffer underrun in i386-dis.c.
@ 2014-01-09 18:26 Roland McGrath
  2014-01-09 18:31 ` H.J. Lu
  0 siblings, 1 reply; 4+ messages in thread
From: Roland McGrath @ 2014-01-09 18:26 UTC (permalink / raw)
  To: binutils, gdb-patches; +Cc: Bradley Nelson

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?


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.  */

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2014-01-09 19:28 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-01-09 18:26 [PATCH] Fix buffer underrun in i386-dis.c Roland McGrath
2014-01-09 18:31 ` H.J. Lu
2014-01-09 19:03   ` Pedro Alves
2014-01-09 19:28     ` Roland McGrath

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).