Skip to content

Commit

Permalink
platform/x86: think-lmi: Avoid potential read before start of the buffer
Browse files Browse the repository at this point in the history
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 <markpearson@lenovo.com>
Reported-by: Dan Carpenter <dan.carpenter@oracle.com>
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Link: https://lore.kernel.org/r/20210609151752.156902-2-hdegoede@redhat.com
  • Loading branch information
Hans de Goede committed Jun 16, 2021
1 parent 86bb2e3 commit 0ddcf3a
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion drivers/platform/x86/think-lmi.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 0ddcf3a

Please sign in to comment.