mtdparts: fixed buffer overflow bug
authorKay Potthoff <kaypotthoff@gmail.com>
Tue, 17 Jul 2018 06:19:39 +0000 (08:19 +0200)
committerTom Rini <trini@konsulko.com>
Tue, 24 Jul 2018 13:25:23 +0000 (09:25 -0400)
In the case that there was no name defined for a partition the
code assumes that name_len is 22 and therefore allocates exactly
that space for a dummy name. But the function sprintf() first
resolves "0x%08llx@0x%08llx" to a string that is longer than 22
bytes. This leads to a buffer overflow. The replacement function
snprintf() limits the copied bytes to name_len and therefore
avoids the buffer overflow.

Signed-off-by: Kay Potthoff <Kay.Potthoff@microsys.de>
cmd/mtdparts.c

index c401009..0da3afd 100644 (file)
@@ -690,7 +690,7 @@ static int part_parse(const char *const partdef, const char **ret, struct part_i
                part->auto_name = 0;
        } else {
                /* auto generated name in form of size@offset */
-               sprintf(part->name, "0x%08llx@0x%08llx", size, offset);
+               snprintf(part->name, name_len, "0x%08llx@0x%08llx", size, offset);
                part->auto_name = 1;
        }