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.
This commit is contained in:
Nick Clifton 2017-06-19 15:57:19 +01:00
parent bc21b167eb
commit d16fdddb4e
2 changed files with 21 additions and 12 deletions

View file

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

View file

@ -1981,22 +1981,25 @@ disassemble_bytes (struct disassemble_info * inf,
if (pb > octets)
pb = octets;
for (; j < addr_offset * opb + pb; j += bpc)
{
/* PR 21619: Check for a buffer ending early. */
if (j + bpc <= stop_offset * opb)
{
int k;
if (bpc > 1 && inf->display_endian == BFD_ENDIAN_LITTLE)
if (inf->display_endian == BFD_ENDIAN_LITTLE)
{
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 (' ');
}
}
putchar (' ');
}
}
}