[U-Boot] [PATCH v2 08/13] disk: part_dos: Fix signed shift overflow

Eugeniu Rosca roscaeugeniu at gmail.com
Sun Aug 26 23:13:26 UTC 2018


Fix the following UBSAN report:
 ====================================================================
 UBSAN: Undefined behaviour in disk/part_dos.c:30:22
 left shift of 209 by 24 places cannot be represented in type 'int'
 ====================================================================

Steps to reproduce the above:
* echo CONFIG_UBSAN=y >> configs/qemu-x86_defconfig
* make ARCH=x86 qemu-x86_defconfig all
* qemu-system-i386 --version
  QEMU emulator version 2.5.0 (Debian 1:2.5+dfsg-5ubuntu10.31)
* qemu-system-i386 --nographic -bios u-boot.rom
* bootefi selftest

Fixes: fe8c2806cdba ("Initial revision")
Signed-off-by: Eugeniu Rosca <erosca at de.adit-jv.com>
---

Changes in v2:
 - None. Newly pushed.
---
 disk/part_dos.c | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)

diff --git a/disk/part_dos.c b/disk/part_dos.c
index 936cee0d36ce..e19695846a95 100644
--- a/disk/part_dos.c
+++ b/disk/part_dos.c
@@ -27,11 +27,10 @@
  */
 static inline unsigned int le32_to_int(unsigned char *le32)
 {
-    return ((le32[3] << 24) +
-	    (le32[2] << 16) +
-	    (le32[1] << 8) +
-	     le32[0]
-	   );
+	return (((unsigned int)le32[3] << 24) +
+		((unsigned int)le32[2] << 16) +
+		((unsigned int)le32[1] << 8) +
+		 (unsigned int)le32[0]);
 }
 
 static inline int is_extended(int part_type)
-- 
2.18.0



More information about the U-Boot mailing list