Skip to content

Commit

Permalink
Cast to unsigned type when interpreting HID descriptor length bytes (…
Browse files Browse the repository at this point in the history
…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 networkupstools#1261, closes networkupstools#1312.
  • Loading branch information
nbriggs committed Feb 28, 2022
1 parent e121856 commit 81d9dd6
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion drivers/libusb0.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 81d9dd6

Please sign in to comment.