Skip to content

Commit ac75a04

Browse files
pyma1Jiri Kosina
authored andcommitted
HID: i2c-hid: fix size check and type usage
When convert char array with signed int, if the inbuf[x] is negative then upper bits will be set to 1. Fix this by using u8 instead of char. ret_size has to be at least 3, hid_input_report use it after minus 2 bytes. Cc: [email protected] Signed-off-by: Aaron Ma <[email protected]> Signed-off-by: Jiri Kosina <[email protected]>
1 parent bbca80b commit ac75a04

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

drivers/hid/i2c-hid/i2c-hid.c

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -144,10 +144,10 @@ struct i2c_hid {
144144
* register of the HID
145145
* descriptor. */
146146
unsigned int bufsize; /* i2c buffer size */
147-
char *inbuf; /* Input buffer */
148-
char *rawbuf; /* Raw Input buffer */
149-
char *cmdbuf; /* Command buffer */
150-
char *argsbuf; /* Command arguments buffer */
147+
u8 *inbuf; /* Input buffer */
148+
u8 *rawbuf; /* Raw Input buffer */
149+
u8 *cmdbuf; /* Command buffer */
150+
u8 *argsbuf; /* Command arguments buffer */
151151

152152
unsigned long flags; /* device flags */
153153
unsigned long quirks; /* Various quirks */
@@ -455,7 +455,8 @@ static int i2c_hid_hwreset(struct i2c_client *client)
455455

456456
static void i2c_hid_get_input(struct i2c_hid *ihid)
457457
{
458-
int ret, ret_size;
458+
int ret;
459+
u32 ret_size;
459460
int size = le16_to_cpu(ihid->hdesc.wMaxInputLength);
460461

461462
if (size > ihid->bufsize)
@@ -480,7 +481,7 @@ static void i2c_hid_get_input(struct i2c_hid *ihid)
480481
return;
481482
}
482483

483-
if (ret_size > size) {
484+
if ((ret_size > size) || (ret_size <= 2)) {
484485
dev_err(&ihid->client->dev, "%s: incomplete report (%d/%d)\n",
485486
__func__, size, ret_size);
486487
return;

0 commit comments

Comments
 (0)