Fix a bogus error message from the DWARF LEB129 decoder when trying to read a signed LEB128 value containing the largest possible signed negative integer value.

PR 26548
	* dwarf.c (read_leb128): When checking for overflow of a signed
	read, use a signed shift.
This commit is contained in:
Nick Clifton
2020-08-28 16:04:49 +01:00
parent a1e60a1bdc
commit 08d7da7dc9
2 changed files with 27 additions and 7 deletions

View File

@ -1,3 +1,9 @@
2020-08-28 Nick Clifton <nickc@redhat.com>
PR 26548
* dwarf.c (read_leb128): When checking for overflow of a signed
read, use a signed shift.
2020-08-28 Cooper Qu <cooper.qu@linux.alibaba.com> 2020-08-28 Cooper Qu <cooper.qu@linux.alibaba.com>
* readelf.c (get_csky_section_type_name): New. * readelf.c (get_csky_section_type_name): New.

View File

@ -345,20 +345,34 @@ read_leb128 (unsigned char *data,
while (data < end) while (data < end)
{ {
unsigned char byte = *data++; unsigned char byte = *data++;
bfd_boolean cont = (byte & 0x80) ? TRUE : FALSE;
byte &= 0x7f;
num_read++; num_read++;
if (shift < sizeof (result) * 8) if (shift < sizeof (result) * 8)
{ {
result |= ((dwarf_vma) (byte & 0x7f)) << shift; result |= ((dwarf_vma) byte) << shift;
if ((result >> shift) != (byte & 0x7f)) if (sign)
/* Overflow. */ {
status |= 2; if ((((dwarf_signed_vma) result >> shift) & 0x7f) != byte)
/* Overflow. */
status |= 2;
}
else if ((result >> shift) != byte)
{
/* Overflow. */
status |= 2;
}
shift += 7; shift += 7;
} }
else if ((byte & 0x7f) != 0) else if (byte != 0)
status |= 2; {
status |= 2;
}
if ((byte & 0x80) == 0) if (!cont)
{ {
status &= ~1; status &= ~1;
if (sign && (shift < 8 * sizeof (result)) && (byte & 0x40)) if (sign && (shift < 8 * sizeof (result)) && (byte & 0x40))