Skip to contentSkip to conversation

platform/x86: think-lmi: Add WMI interface support on Lenovo platforms

bug report Dan Carpenter 1 participant 1 message Jun 9, 2021 x86 platform drivers

lore
Share & tools
lore
#0 lore raw

Hello Mark Pearson,

The patch a7314b3b1d8a: "platform/x86: think-lmi: Add WMI interface support on Lenovo platforms" from May 30, 2021, leads to the following static checker warning:

	drivers/platform/x86/think-lmi.c:453 kbdlang_store()
	error: iterator underflow 'setting->kbdlang' (-1),1-3

drivers/platform/x86/think-lmi.c
438 static ssize_t kbdlang_store(struct kobject *kobj,
439 struct kobj_attribute *attr,
440 const char *buf, size_t count)
441 {
442 struct tlmi_pwd_setting *setting = to_tlmi_pwd_setting(kobj);
443 int length;
444
445 length = strlen(buf);

"count" can never be zero, but strlen(buf) can be zero.

446 if (buf[length-1] == '\n')

                        ^^^^^^^^

So this code can read before the start of the buffer, potentially leading to an Oops.

   447                  length--;
   448  
   449          if (!length || (length >= TLMI_LANG_MAXLEN))
   450                  return -EINVAL;
   451  
   452          memcpy(setting->kbdlang, buf, length);
   453          setting->kbdlang[length] = '\0';
   454          return count;
   455  }

regards,
dan carpenter