]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commit
read_leb128 overflow checking
authorAlan Modra <amodra@gmail.com>
Tue, 16 Feb 2021 13:16:40 +0000 (23:46 +1030)
committerAlan Modra <amodra@gmail.com>
Wed, 17 Feb 2021 06:27:59 +0000 (16:57 +1030)
commitb9b204b31164188228e585526feb4b4d7d80a114
tree454c249a57dfc0a9f98074275cae07bc7c0ae4d7
parent0d6aab77761274e479ca443f8bcb35a0eee3a4c4
read_leb128 overflow checking

There is a tiny error left in dwarf.c:read_leb128 after Nick fixed the
signed overflow problem in code I wrote.  It's to do with sleb128
values that have unnecessary excess bytes.  For example, -1 is
represented as 0x7f, the most efficient encoding, but also as
0xff,0x7f or 0xff,0xff,0x7f and so on.  None of these sequences
overflow any size signed value, but read_leb128 will report an
overflow given enough excess bytes.  This patch fixes that problem,
and since the proper test for signed values with excess bytes can
easily be adapted to also test a sleb byte with just some bits that
overflow the result, I changed the code to not use signed right
shifts.  (The C standard ISO/IEC 9899:1999 6.5.7 says signed right
shifts of negative values have an implementation defined value.  A
long time ago I even used a C compiler for a certain microprocessor
that always did unsigned right shifts.  Mind you, it is very unlikely
to be compiling binutils with such a compiler.)

bfd/
* wasm-module.c: Guard include of limits.h.
(CHAR_BIT): Provide backup define.
(wasm_read_leb128): Use CHAR_BIT to size "result" in bits.
Correct signed overflow checking.
opcodes/
* wasm32-dis.c: Include limits.h.
(CHAR_BIT): Provide backup define.
(wasm_read_leb128): Use CHAR_BIT to size "result" in bits.
Correct signed overflow checking.
binutils/
* dwarf.c: Include limits.h.
(CHAR_BIT): Provide backup define.
(read_leb128): Use CHAR_BIT to size "result" in bits.  Correct
signed overflow checking.
* testsuite/binutils-all/pr26548.s,
* testsuite/binutils-all/pr26548.d,
* testsuite/binutils-all/pr26548e.d: New tests.
* testsuite/binutils-all/readelf.exp: Run them.
(readelf_test): Drop unused "xfails" parameter.  Update all uses.
bfd/ChangeLog
bfd/wasm-module.c
binutils/ChangeLog
binutils/dwarf.c
binutils/testsuite/binutils-all/pr26548.d [new file with mode: 0644]
binutils/testsuite/binutils-all/pr26548.s [new file with mode: 0644]
binutils/testsuite/binutils-all/pr26548e.d [new file with mode: 0644]
binutils/testsuite/binutils-all/readelf.exp
opcodes/ChangeLog
opcodes/wasm32-dis.c