platform/x86: think-lmi: Avoid potential read before start of the buffer

If length equals 0 then reading buf[length-1] will read before the start
of the buffer.

Avoid this by moving the length == 0 check up.

Cc: Mark Pearson <[email protected]>
Reported-by: Dan Carpenter <[email protected]>
Signed-off-by: Hans de Goede <[email protected]>
Link: https://lore.kernel.org/r/[email protected]
This commit is contained in:
Hans de Goede
2021-06-16 17:47:55 +02:00
parent 86bb2e3daf
commit 0ddcf3a6b4
+4 -1
View File
@@ -443,10 +443,13 @@ static ssize_t kbdlang_store(struct kobject *kobj,
int length;
length = strlen(buf);
if (!length)
return -EINVAL;
if (buf[length-1] == '\n')
length--;
if (!length || (length >= TLMI_LANG_MAXLEN))
if (length >= TLMI_LANG_MAXLEN)
return -EINVAL;
memcpy(setting->kbdlang, buf, length);