]> git.baikalelectronics.ru Git - kernel.git/commitdiff
HID: hid-lg4ff: Add check for empty lbuf
authorAnastasia Belova <abelova@astralinux.ru>
Fri, 11 Nov 2022 12:55:11 +0000 (15:55 +0300)
committerJiri Kosina <jkosina@suse.cz>
Mon, 14 Nov 2022 22:56:52 +0000 (23:56 +0100)
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: bf2fb4c11b50 ("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>
drivers/hid/hid-lg4ff.c

index 5e6a0cef2a06d061035520a28e24cc4488859498..e3fcf1353fb3b701c0ec821be638f0a154aa9f78 100644 (file)
@@ -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);