Commit 2260209c authored by Vasiliy Kulikov's avatar Vasiliy Kulikov Committed by Linus Torvalds

drivers/leds/leds-lp5521.c: fix potential buffer overflow

The code doesn't check first sscanf() return value.  If first sscanf()
failed then c contains some garbage.  It might lead to reading
uninitialised stack data in the second sscanf() call.
Signed-off-by: default avatarVasiliy Kulikov <segoon@openwall.com>
Cc: Richard Purdie <rpurdie@rpsys.net>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent 6db26ffc
...@@ -373,6 +373,8 @@ static int lp5521_do_store_load(struct lp5521_engine *engine, ...@@ -373,6 +373,8 @@ static int lp5521_do_store_load(struct lp5521_engine *engine,
while ((offset < len - 1) && (i < LP5521_PROGRAM_LENGTH)) { while ((offset < len - 1) && (i < LP5521_PROGRAM_LENGTH)) {
/* separate sscanfs because length is working only for %s */ /* separate sscanfs because length is working only for %s */
ret = sscanf(buf + offset, "%2s%n ", c, &nrchars); ret = sscanf(buf + offset, "%2s%n ", c, &nrchars);
if (ret != 2)
goto fail;
ret = sscanf(c, "%2x", &cmd); ret = sscanf(c, "%2x", &cmd);
if (ret != 1) if (ret != 1)
goto fail; goto fail;
......
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