From 81d9dd6309e36df158fb4556678a0acecf95d5e4 Mon Sep 17 00:00:00 2001 From: Nick Briggs Date: Mon, 28 Feb 2022 12:32:19 -0800 Subject: [PATCH] Cast to unsigned type when interpreting HID descriptor length bytes (libusb 0.1) The libusb 0.1 interface definition declares a (signed) char type for control messages. The HID descriptor length contained within a control message is intended to be interpreted as a pair of unsigned bytes so we must cast to uint8_t when doing the arithmetic rather than trip over the sign bit. Closes #1261, closes #1312. --- drivers/libusb0.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/libusb0.c b/drivers/libusb0.c index adf098ba31..e7f16c9003 100644 --- a/drivers/libusb0.c +++ b/drivers/libusb0.c @@ -377,7 +377,7 @@ static int libusb_open(usb_dev_handle **udevp, upsdebug_hex(3, "HID descriptor, method 1", buf, 9); - rdlen1 = buf[7] | (buf[8] << 8); + rdlen1 = (uint8_t)buf[7] | ((uint8_t)buf[8] << 8); } if (rdlen1 < -1) {