This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
Re: [PATCH][Arm] gas: fix out of range conditional branch (PR/24991)
- From: Andreas Schwab <schwab at suse dot de>
- To: Nick Clifton <nickc at redhat dot com>
- Cc: Tamar Christina <Tamar dot Christina at arm dot com>, "binutils\@sourceware.org" <binutils at sourceware dot org>, nd <nd at arm dot com>, Richard Earnshaw <Richard dot Earnshaw at arm dot com>, Ramana Radhakrishnan <Ramana dot Radhakrishnan at arm dot com>
- Date: Mon, 23 Sep 2019 12:21:00 +0200
- Subject: Re: [PATCH][Arm] gas: fix out of range conditional branch (PR/24991)
- References: <20190919125957.GA801@arm.com> <b76cc1f5-813b-aab8-ced8-1ea174f2d804@redhat.com>
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."