[binutils-gdb] PR26458 UBSAN: elf32-i386.c:3615 left shift of negative value

Alan Modra amodra@sourceware.org
Wed Aug 26 13:54:56 GMT 2020


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

commit 1673aff56987e560ab429beba0d77b85a1c4e064
Author: Alan Modra <amodra@gmail.com>
Date:   Wed Aug 26 11:00:22 2020 +0930

    PR26458 UBSAN: elf32-i386.c:3615 left shift of negative value
    
    Happens when poking symbol index -2 into r_info.  (The index is
    updated before writing out to file.)
    
            PR 26458
            * elf/common.h (ELF32_R_INFO): Cast symbol index to unsigned.

Diff:
---
 include/ChangeLog    | 5 +++++
 include/elf/common.h | 2 +-
 2 files changed, 6 insertions(+), 1 deletion(-)

diff --git a/include/ChangeLog b/include/ChangeLog
index 2ec02dc5000..b51a186fc6e 100644
--- a/include/ChangeLog
+++ b/include/ChangeLog
@@ -1,3 +1,8 @@
+2020-08-26  Alan Modra  <amodra@gmail.com>
+
+	PR 26458
+	* elf/common.h (ELF32_R_INFO): Cast symbol index to unsigned.
+
 2020-08-24  Cooper Qu  <cooper.qu@linux.alibaba.com>
 
 	* opcode/csky.h (CSKYV2_ISA_10E60): New.
diff --git a/include/elf/common.h b/include/elf/common.h
index 2138868c9b9..efef412caaf 100644
--- a/include/elf/common.h
+++ b/include/elf/common.h
@@ -942,7 +942,7 @@
 
 #define ELF32_R_SYM(i)		((i) >> 8)
 #define ELF32_R_TYPE(i)		((i) & 0xff)
-#define ELF32_R_INFO(s,t)	(((s) << 8) + ((t) & 0xff))
+#define ELF32_R_INFO(s,t)	(((unsigned) (s) << 8) + ((t) & 0xff))
 
 #define ELF64_R_SYM(i)		((i) >> 32)
 #define ELF64_R_TYPE(i)		((i) & 0xffffffff)


More information about the Binutils-cvs mailing list