[PATCH] flash_otp_write: fix a buffer overflow on NAND with write size > 2048

Uwe Kleine-König u.kleine-koenig at pengutronix.de
Thu Feb 28 04:42:26 EST 2013


I'm not aware of any chip having a write size bigger than 2048 today.
Still checking for that instead of a sleeping problem to bite us maybe
in a few years is easy.

Signed-off-by: Uwe Kleine-König <u.kleine-koenig at pengutronix.de>
---
 flash_otp_write.c |    6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/flash_otp_write.c b/flash_otp_write.c
index 0aa872e..5114e6b 100644
--- a/flash_otp_write.c
+++ b/flash_otp_write.c
@@ -82,6 +82,12 @@ int main(int argc,char *argv[])
 	else
 		len = 256;
 
+	if (len > sizeof(buf)) {
+		printf("huh, writesize (%d) bigger than buffer (%zu)\n",
+				len, sizeof(buf));
+		return ENOMEM;
+	}
+
 	wrote = 0;
 	while ((size = xread(0, buf, len))) {
 		if (size < 0) {
-- 
1.7.10.4




More information about the linux-mtd mailing list