[PATCH][Arm] gas: fix out of range conditional branch (PR/24991)

Andreas Schwab schwab@suse.de
Mon Sep 23 10:21:00 GMT 2019


On Sep 23 2019, Nick Clifton <nickc@redhat.com> wrote:

> Hi Tamar,
>
>   Being paranoid here....
>
>> +/* Perform range checks on positive and negative overflows by checking if the
>> +   VALUE given fits within the range of an BITS sized immediate.  */
>> +static bfd_boolean out_of_range_p (offsetT value, bfd_vma bits)
>> +{
>> +  return (value & ~((1 << bits)-1))
>> +         && ((value & ~((1 << bits)-1)) != ~((1 << bits)-1));
>> +}
>
> If bits is a large number then these shifts could overflow.  I would
> recommend adding a range check first.  Plus you should allow for the
> fact that sizeof (bits) and sizeof (value) could be small if the code
> is compiled for a 32-bit host...

The shifts should be performed in offsetT (or its unsigned equivalent),
not int.  bits can be int instead of bfd_vma.

Andreas.

-- 
Andreas Schwab, SUSE Labs, schwab@suse.de
GPG Key fingerprint = 0196 BAD8 1CE9 1970 F4BE  1748 E4D4 88E3 0EEA B9D7
"And now for something completely different."



More information about the Binutils mailing list