aboutsummaryrefslogtreecommitdiff
path: root/binutils/objdump.c
diff options
context:
space:
mode:
authorNick Clifton <nickc@redhat.com>2017-06-14 16:50:03 +0100
committerNick Clifton <nickc@redhat.com>2017-06-14 16:50:03 +0100
commitae87f7e73eba29bd38b3a9684a10b948ed715612 (patch)
tree2623d2073e3b3b8ff831da059af8e7d019833d51 /binutils/objdump.c
parent6394c606997f88acfc80de4dff33a4ae2de987b4 (diff)
downloadgdb-ae87f7e73eba29bd38b3a9684a10b948ed715612.zip
gdb-ae87f7e73eba29bd38b3a9684a10b948ed715612.tar.gz
gdb-ae87f7e73eba29bd38b3a9684a10b948ed715612.tar.bz2
Fix address violation when disassembling a corrupt binary.
PR binutils/21580 binutils * objdump.c (disassemble_bytes): Check for buffer overrun when printing out rae insns. ld * testsuite/ld-nds32/diff.d: Adjust expected output.
Diffstat (limited to 'binutils/objdump.c')
-rw-r--r--binutils/objdump.c27
1 files changed, 15 insertions, 12 deletions
diff --git a/binutils/objdump.c b/binutils/objdump.c
index 6dc8318..05402ed 100644
--- a/binutils/objdump.c
+++ b/binutils/objdump.c
@@ -1918,20 +1918,23 @@ disassemble_bytes (struct disassemble_info * inf,
for (j = addr_offset * opb; j < addr_offset * opb + pb; j += bpc)
{
- int k;
-
- if (bpc > 1 && inf->display_endian == BFD_ENDIAN_LITTLE)
- {
- for (k = bpc - 1; k >= 0; k--)
- printf ("%02x", (unsigned) data[j + k]);
- putchar (' ');
- }
- else
+ /* PR 21580: Check for a buffer ending early. */
+ if (j + bpc <= stop_offset * opb)
{
- for (k = 0; k < bpc; k++)
- printf ("%02x", (unsigned) data[j + k]);
- putchar (' ');
+ int k;
+
+ if (inf->display_endian == BFD_ENDIAN_LITTLE)
+ {
+ for (k = bpc - 1; k >= 0; k--)
+ printf ("%02x", (unsigned) data[j + k]);
+ }
+ else
+ {
+ for (k = 0; k < bpc; k++)
+ printf ("%02x", (unsigned) data[j + k]);
+ }
}
+ putchar (' ');
}
for (; pb < octets_per_line; pb += bpc)