Skip to contentSkip to conversation

USB: sisusbvga: Fix a UB casued by left shifting a negative value

PATCH New Changming 1 participant 1 message Jul 11, 2020

Subsystems (2)
lore
Share & tools
lore

Changming

author
#0 lore raw

PATCH 1/1 USB: sisusbvga: Fix a UB casued by left shifting a negative value

From: Changming Liu <[email protected]>

The char buffer buf, receives data directly from user space, so its content might be negative and its elements are left shifted to form an unsigned integer.

Since left shifting a negative value is undefined behavior, thus change the char to u8 to elimintate this UB.

---
 drivers/usb/misc/sisusbvga/sisusb.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/usb/misc/sisusbvga/sisusb.c +1 -1
index fc8a5da4a07c..0734e6dd9386 100644
@@ -761,7 +761,7 @@ static int sisusb_write_mem_bulk(struct sisusb_usb_data *sisusb, u32 addr,
 	u8   swap8, fromkern = kernbuffer ? 1 : 0;
 	u16  swap16;
 	u32  swap32, flag = (length >> 28) & 1;
-	char buf[4];
+	u8 buf[4];
 
 	/* if neither kernbuffer not userbuffer are given, assume
 	 * data in obuf
Signature · 1 line
2.17.1