]> www.infradead.org Git - mtd-utils.git/commitdiff
flash_otp_write: fix a buffer overflow on NAND with write size > 2048
authorUwe Kleine-König <u.kleine-koenig@pengutronix.de>
Thu, 28 Feb 2013 09:42:26 +0000 (10:42 +0100)
committerArtem Bityutskiy <artem.bityutskiy@linux.intel.com>
Mon, 11 Mar 2013 07:51:29 +0000 (09:51 +0200)
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@pengutronix.de>
Signed-off-by: Artem Bityutskiy <artem.bityutskiy@linux.intel.com>
flash_otp_write.c

index 3515eee736118cf93dd1f20a4eae0ff9b6dc962b..eaca5e18cc3610db8ea1a502909e5f993cf236c9 100644 (file)
@@ -83,6 +83,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) {