From: Nick Clifton Date: Wed, 14 Jun 2017 15:50:03 +0000 (+0100) Subject: Fix address violation when disassembling a corrupt binary. X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=ae87f7e73eba29bd38b3a9684a10b948ed715612;p=binutils-gdb.git 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. --- diff --git a/binutils/objdump.c b/binutils/objdump.c index 6dc8318a5a9..05402edbebf 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) diff --git a/ld/ChangeLog b/ld/ChangeLog index 8d5246424ba..72777eeea96 100644 --- a/ld/ChangeLog +++ b/ld/ChangeLog @@ -1,3 +1,8 @@ +2017-06-14 Nick Clifton + + PR binutils/21580 + * testsuite/ld-nds32/diff.d: Adjust expected output. + 2017-06-14 H.J. Lu PR ld/20022 diff --git a/ld/testsuite/ld-nds32/diff.d b/ld/testsuite/ld-nds32/diff.d index ef7958666fe..1aff7366def 100644 --- a/ld/testsuite/ld-nds32/diff.d +++ b/ld/testsuite/ld-nds32/diff.d @@ -7,9 +7,9 @@ Disassembly of section .data: 00008000 (7e 00 00 00|00 00 00 7e).* -00008004 (7e 00 7e fe|00 7e 7e fe).* -00008006 7e fe 00 fe.* -00008007 fe 00.* +00008004 (7e 00|00 7e).* +00008006 7e.* +00008007 fe.* ... 00008009 fe 00.* .*