[binutils-gdb] ubsan: arc: shift exponent 32 is too large for 32-bit type 'int'

Alan Modra amodra@sourceware.org
Wed Dec 11 01:13:00 GMT 2019


https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=a11db3e9f3a679601f41671a9e7f54c37f2c5073

commit a11db3e9f3a679601f41671a9e7f54c37f2c5073
Author: Alan Modra <amodra@gmail.com>
Date:   Tue Dec 10 19:09:47 2019 +1030

    ubsan: arc: shift exponent 32 is too large for 32-bit type 'int'
    
    When operand->bits is 32, the following results in UB.
    value = (insn >> operand->shift) & ((1 << operand->bits) - 1);
    
    	* arc-dis.c (find_format_from_table): Use ull constant when
    	shifting by up to 32.

Diff:
---
 opcodes/ChangeLog | 5 +++++
 opcodes/arc-dis.c | 2 +-
 2 files changed, 6 insertions(+), 1 deletion(-)

diff --git a/opcodes/ChangeLog b/opcodes/ChangeLog
index 3460b3e..d3f1e69 100644
--- a/opcodes/ChangeLog
+++ b/opcodes/ChangeLog
@@ -1,5 +1,10 @@
 2019-12-11  Alan Modra  <amodra@gmail.com>
 
+	* arc-dis.c (find_format_from_table): Use ull constant when
+	shifting by up to 32.
+
+2019-12-11  Alan Modra  <amodra@gmail.com>
+
 	PR 25270
 	* aarch64-dis.c (aarch64_decode_variant_using_iclass): Return
 	false when field is zero for sve_size_tsz_bhs.
diff --git a/opcodes/arc-dis.c b/opcodes/arc-dis.c
index 3c88c33..a038fa0 100644
--- a/opcodes/arc-dis.c
+++ b/opcodes/arc-dis.c
@@ -295,7 +295,7 @@ find_format_from_table (struct disassemble_info *info,
 	  if (operand->extract)
 	    value = (*operand->extract) (insn, &invalid);
 	  else
-	    value = (insn >> operand->shift) & ((1 << operand->bits) - 1);
+	    value = (insn >> operand->shift) & ((1ull << operand->bits) - 1);
 
 	  /* Check for LIMM indicator.  If it is there, then make sure
 	     we pick the right format.  */



More information about the Binutils-cvs mailing list