aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNick Clifton <nickc@redhat.com>2017-06-19 15:57:19 +0100
committerNick Clifton <nickc@redhat.com>2017-06-19 15:57:19 +0100
commitd16fdddb4e96e9e7bcfce6fe487b321c54b2c7c7 (patch)
treebe6c263d9097282435ac74e6412e68da7510e5e8
parentbc21b167eb0106eb31d946a0eb5acfb7e4d5d8a1 (diff)
downloadgdb-d16fdddb4e96e9e7bcfce6fe487b321c54b2c7c7.zip
gdb-d16fdddb4e96e9e7bcfce6fe487b321c54b2c7c7.tar.gz
gdb-d16fdddb4e96e9e7bcfce6fe487b321c54b2c7c7.tar.bz2
Fix address violation when attempting to display disassembled data.
PR binutils/21619 * objdump.c (disassemble_bytes): Check that there is sufficient data available before attempting to display it.
-rw-r--r--binutils/ChangeLog6
-rw-r--r--binutils/objdump.c27
2 files changed, 21 insertions, 12 deletions
diff --git a/binutils/ChangeLog b/binutils/ChangeLog
index 0766e67..6997db9 100644
--- a/binutils/ChangeLog
+++ b/binutils/ChangeLog
@@ -1,3 +1,9 @@
+2017-06-19 Nick Clifton <nickc@redhat.com>
+
+ PR binutils/21619
+ * objdump.c (disassemble_bytes): Check that there is sufficient
+ data available before attempting to display it.
+
2017-06-06 Simon Marchi <simon.marchi@ericsson.com>
* sysinfo.y: Free memory allocated by token NAME.
diff --git a/binutils/objdump.c b/binutils/objdump.c
index 05402ed..16e1f0e 100644
--- a/binutils/objdump.c
+++ b/binutils/objdump.c
@@ -1982,20 +1982,23 @@ disassemble_bytes (struct disassemble_info * inf,
pb = octets;
for (; j < addr_offset * opb + pb; j += bpc)
{
- int k;
-
- if (bpc > 1 && inf->display_endian == BFD_ENDIAN_LITTLE)
+ /* PR 21619: Check for a buffer ending early. */
+ if (j + bpc <= stop_offset * opb)
{
- for (k = bpc - 1; k >= 0; k--)
- printf ("%02x", (unsigned) data[j + k]);
- putchar (' ');
- }
- else
- {
- 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 (' ');
}
}
}