Commit 0ddcf3a6 authored by Hans de Goede's avatar Hans de Goede

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 <markpearson@lenovo.com>
Reported-by: default avatarDan Carpenter <dan.carpenter@oracle.com>
Signed-off-by: default avatarHans de Goede <hdegoede@redhat.com>
Link: https://lore.kernel.org/r/20210609151752.156902-2-hdegoede@redhat.com
parent 86bb2e3d
...@@ -443,10 +443,13 @@ static ssize_t kbdlang_store(struct kobject *kobj, ...@@ -443,10 +443,13 @@ static ssize_t kbdlang_store(struct kobject *kobj,
int length; int length;
length = strlen(buf); length = strlen(buf);
if (!length)
return -EINVAL;
if (buf[length-1] == '\n') if (buf[length-1] == '\n')
length--; length--;
if (!length || (length >= TLMI_LANG_MAXLEN)) if (length >= TLMI_LANG_MAXLEN)
return -EINVAL; return -EINVAL;
memcpy(setting->kbdlang, buf, length); memcpy(setting->kbdlang, buf, length);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment