drivers/leds/leds-lp5521.c: fix potential buffer overflow
authorVasiliy Kulikov <segoon@openwall.com>
Thu, 13 Jan 2011 00:59:14 +0000 (16:59 -0800)
committerLinus Torvalds <torvalds@linux-foundation.org>
Thu, 13 Jan 2011 16:03:05 +0000 (08:03 -0800)
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: Vasiliy Kulikov <segoon@openwall.com>
Cc: Richard Purdie <rpurdie@rpsys.net>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
drivers/leds/leds-lp5521.c

index 33facd0c45d10c146867cbf2e74c050a360166b5..e881a75dc39dbaf3616da8df624f5d6695ef7b63 100644 (file)
@@ -373,6 +373,8 @@ static int lp5521_do_store_load(struct lp5521_engine *engine,
        while ((offset < len - 1) && (i < LP5521_PROGRAM_LENGTH)) {
                /* separate sscanfs because length is working only for %s */
                ret = sscanf(buf + offset, "%2s%n ", c, &nrchars);
+               if (ret != 2)
+                       goto fail;
                ret = sscanf(c, "%2x", &cmd);
                if (ret != 1)
                        goto fail;