]> git.sur5r.net Git - u-boot/commitdiff
mtdparts: Fix final outstanding issue reported by Coverity
authorTom Rini <trini@konsulko.com>
Mon, 21 Aug 2017 00:05:40 +0000 (20:05 -0400)
committerTom Rini <trini@konsulko.com>
Sat, 26 Aug 2017 18:56:13 +0000 (14:56 -0400)
As part of fixing the previously reported issues, it was missed that in
the case of mtdparts_init() we need to make sure that tmp_ep is long
enough to contain PARTITION_MAXLEN and a NULL termination.  Then, to be
sure the buffer is NULL terminated, zero the entire buffer rather than
just ensuring the first character is NULL.

Cc: Lothar Waßmann <LW@KARO-electronics.de>
Cc: Maxime Ripard <maxime.ripard@free-electrons.com>
Reported-by: Coverity (CID: 166329)
Signed-off-by: Tom Rini <trini@konsulko.com>
cmd/mtdparts.c

index 72bff92a9aee591060233b5169509ea06b05dffc..6e12275b4083fd3b7d33d762d243f4411abd02a1 100644 (file)
@@ -1726,7 +1726,7 @@ int mtdparts_init(void)
        const char *ids, *parts;
        const char *current_partition;
        int ids_changed;
-       char tmp_ep[PARTITION_MAXLEN];
+       char tmp_ep[PARTITION_MAXLEN + 1];
        char tmp_parts[MTDPARTS_MAXLEN];
 
        debug("\n---mtdparts_init---\n");
@@ -1750,7 +1750,7 @@ int mtdparts_init(void)
 
        /* save it for later parsing, cannot rely on current partition pointer
         * as 'partition' variable may be updated during init */
-       tmp_ep[0] = '\0';
+       memset(tmp_parts, 0, sizeof(tmp_parts));
        if (current_partition)
                strncpy(tmp_ep, current_partition, PARTITION_MAXLEN);