aboutsummaryrefslogtreecommitdiff
path: root/binutils/dwarf.c
diff options
context:
space:
mode:
authorNick Clifton <nickc@redhat.com>2020-08-28 16:04:49 +0100
committerNick Clifton <nickc@redhat.com>2020-08-28 16:04:49 +0100
commit08d7da7dc9e130cbaf072c2588e1b392c2d7503e (patch)
tree874e50e069bc1884bcd310c039f58a1f76131775 /binutils/dwarf.c
parenta1e60a1bdce8f555f45b5f94c059d83abf883567 (diff)
downloadgdb-08d7da7dc9e130cbaf072c2588e1b392c2d7503e.zip
gdb-08d7da7dc9e130cbaf072c2588e1b392c2d7503e.tar.gz
gdb-08d7da7dc9e130cbaf072c2588e1b392c2d7503e.tar.bz2
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.
Diffstat (limited to 'binutils/dwarf.c')
-rw-r--r--binutils/dwarf.c28
1 files changed, 21 insertions, 7 deletions
diff --git a/binutils/dwarf.c b/binutils/dwarf.c
index 5275994..616e534 100644
--- a/binutils/dwarf.c
+++ b/binutils/dwarf.c
@@ -345,20 +345,34 @@ read_leb128 (unsigned char *data,
while (data < end)
{
unsigned char byte = *data++;
+ bfd_boolean cont = (byte & 0x80) ? TRUE : FALSE;
+
+ byte &= 0x7f;
num_read++;
if (shift < sizeof (result) * 8)
{
- result |= ((dwarf_vma) (byte & 0x7f)) << shift;
- if ((result >> shift) != (byte & 0x7f))
- /* Overflow. */
- status |= 2;
+ result |= ((dwarf_vma) byte) << shift;
+ if (sign)
+ {
+ if ((((dwarf_signed_vma) result >> shift) & 0x7f) != byte)
+ /* Overflow. */
+ status |= 2;
+ }
+ else if ((result >> shift) != byte)
+ {
+ /* Overflow. */
+ status |= 2;
+ }
+
shift += 7;
}
- else if ((byte & 0x7f) != 0)
- status |= 2;
+ else if (byte != 0)
+ {
+ status |= 2;
+ }
- if ((byte & 0x80) == 0)
+ if (!cont)
{
status &= ~1;
if (sign && (shift < 8 * sizeof (result)) && (byte & 0x40))