Skip to content

Commit 0ddcf3a

Browse files
committed
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]
1 parent 86bb2e3 commit 0ddcf3a

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

drivers/platform/x86/think-lmi.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -443,10 +443,13 @@ static ssize_t kbdlang_store(struct kobject *kobj,
443443
int length;
444444

445445
length = strlen(buf);
446+
if (!length)
447+
return -EINVAL;
448+
446449
if (buf[length-1] == '\n')
447450
length--;
448451

449-
if (!length || (length >= TLMI_LANG_MAXLEN))
452+
if (length >= TLMI_LANG_MAXLEN)
450453
return -EINVAL;
451454

452455
memcpy(setting->kbdlang, buf, length);

0 commit comments

Comments
 (0)