From: Nick Clifton Date: Thu, 3 Sep 2020 14:52:53 +0000 (+0100) Subject: Import a patch from mainline to fix a spurious overflow error when decoding negative... X-Git-Tag: binutils-2_35_1~29 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=1f1ded87c9250deb986067eac6d53663f3f69e09;p=thirdparty%2Fbinutils-gdb.git Import a patch from mainline to fix a spurious overflow error when decoding negative LEB128 values. PR 26548 * dwarf.c (read_leb128): When checking for overflow of a signed read, use a signed shift. --- diff --git a/binutils/ChangeLog b/binutils/ChangeLog index 2e7fecee8ca..0ccacc63e5d 100644 --- a/binutils/ChangeLog +++ b/binutils/ChangeLog @@ -1,3 +1,12 @@ +2020-09-03 Nick Clifton + + Import from mainline: + 2020-08-28 Nick Clifton + + PR 26548 + * dwarf.c (read_leb128): When checking for overflow of a signed + read, use a signed shift. + 2020-08-25 Nick Clifton Backport from the mainline: diff --git a/binutils/dwarf.c b/binutils/dwarf.c index bdabd9c4baa..cc13fe067f0 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))