Skip to content

Commit

Permalink
HID: hid-lg4ff: Add check for empty lbuf
Browse files Browse the repository at this point in the history
If an empty buf is received, lbuf is also empty. So lbuf is
accessed by index -1.

Found by Linux Verification Center (linuxtesting.org) with SVACE.

Fixes: f31a2de ("HID: hid-lg4ff: Allow switching of Logitech gaming wheels between compatibility modes")
Signed-off-by: Anastasia Belova <abelova@astralinux.ru>
Signed-off-by: Jiri Kosina <jkosina@suse.cz>
  • Loading branch information
Anastasia Belova authored and Jiri Kosina committed Nov 14, 2022
1 parent 9ad6645 commit d180b64
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions drivers/hid/hid-lg4ff.c
Original file line number Diff line number Diff line change
Expand Up @@ -872,6 +872,12 @@ static ssize_t lg4ff_alternate_modes_store(struct device *dev, struct device_att
return -ENOMEM;

i = strlen(lbuf);

if (i == 0) {
kfree(lbuf);
return -EINVAL;
}

if (lbuf[i-1] == '\n') {
if (i == 1) {
kfree(lbuf);
Expand Down

0 comments on commit d180b64

Please sign in to comment.