This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
Re: [PATCH][Binutils][Arm] gas: fix out of range conditional branch (PR/24991)
- From: Nick Clifton <nickc at redhat dot com>
- To: Tamar Christina <Tamar dot Christina at arm dot com>, "binutils at sourceware dot org" <binutils at sourceware dot org>
- Cc: 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 11:06:50 +0100
- Subject: Re: [PATCH][Binutils][Arm] gas: fix out of range conditional branch (PR/24991)
- References: <20190919125957.GA801@arm.com>
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...
Cheers
Nick