Avoid undefined behaviour with signed expressions

PR 17453
bfd/
	* libbfd.c (COERCE16, COERCE32, COERCE64): Use unsigned types.
	(EIGHT_GAZILLION): Delete.
binutils/
	* dwarf.c (read_leb128): Avoid signed overflow.
	(read_debug_line_header): Likewise.
gas/
	* config/tc-i386.c (fits_in_signed_long): Use unsigned param and
	expression to avoid signed overflow.
	(fits_in_signed_byte, fits_in_unsigned_byte, fits_in_unsigned_word,
	fits_in_signed_word, fits_in_unsigned_long): Similarly.
	* expr.c (operand <'-'>): Avoid signed overflow.
	* read.c (s_comm_internal): Likewise.
This commit is contained in:
Alan Modra
2014-10-14 13:36:20 +10:30
parent 9495b2e66f
commit 65879393f0
9 changed files with 43 additions and 26 deletions

View File

@@ -1,3 +1,9 @@
2014-10-14 Alan Modra <amodra@gmail.com>
PR 17453
* dwarf.c (read_leb128): Avoid signed overflow.
(read_debug_line_header): Likewise.
2014-10-14 Alan Modra <amodra@gmail.com>
PR 17453

View File

@@ -259,7 +259,7 @@ read_leb128 (unsigned char *data,
*length_return = num_read;
if (sign && (shift < 8 * sizeof (result)) && (byte & 0x40))
result |= -1L << shift;
result |= (dwarf_vma) -1 << shift;
return result;
}
@@ -2661,14 +2661,10 @@ read_debug_line_header (struct dwarf_section * section,
linfo->li_max_ops_per_insn = 1;
SAFE_BYTE_GET_AND_INC (linfo->li_default_is_stmt, hdrptr, 1, end);
SAFE_BYTE_GET_AND_INC (linfo->li_line_base, hdrptr, 1, end);
SAFE_SIGNED_BYTE_GET_AND_INC (linfo->li_line_base, hdrptr, 1, end);
SAFE_BYTE_GET_AND_INC (linfo->li_line_range, hdrptr, 1, end);
SAFE_BYTE_GET_AND_INC (linfo->li_opcode_base, hdrptr, 1, end);
/* Sign extend the line base field. */
linfo->li_line_base <<= 24;
linfo->li_line_base >>= 24;
* end_of_sequence = data + linfo->li_length + initial_length_size;
return hdrptr;
}