Skip to contentSkip to conversation

leds: leds-lp5521: fix potential buffer overflow

PATCH In review Vasiliy Kulikov 1 participant 1 message Nov 18, 2010

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 3/4 leds: leds-lp5521: 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 buffer overflow in second sscanf() call.

---
Compile tested.

 drivers/leds/leds-lp5521.c |    2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)
drivers/leds/leds-lp5521.c +2 -0
index 3782f31..939319d 100644
@@ -362,6 +362,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;
Signature · 1 line
1.7.0.4