]> git.kernelconcepts.de Git - karo-tx-uboot.git/commitdiff
libfdt: Fix segfault when calling fit_check_format() on corrupt FIT images
authorJon Nalley <lists@bluebot.org>
Wed, 26 Feb 2014 16:32:21 +0000 (11:32 -0500)
committerTom Rini <trini@ti.com>
Thu, 19 Jun 2014 15:18:42 +0000 (11:18 -0400)
It has been observed that fit_check_format() will fail when passed a
corrupt FIT image.  This was tracked down to _fdt_string_eq():
return (strlen(p) == len) && (memcmp(p, s, len) == 0);

In the case of a corrupt FIT image one can't depend on 'p' being NULL
terminated.  I changed it to use strnlen() to fix the issue.

Signed-off-by: Tom Rini <trini@ti.com>
lib/libfdt/fdt_ro.c

index f2154e8370272eeac529644e80a19923902a7265..36af0435254b47cb0d2599836d1c81638266adf8 100644 (file)
@@ -44,7 +44,7 @@ static int _fdt_string_eq(const void *fdt, int stroffset,
 {
        const char *p = fdt_string(fdt, stroffset);
 
-       return (strlen(p) == len) && (memcmp(p, s, len) == 0);
+       return (strnlen(p, len + 1) == len) && (memcmp(p, s, len) == 0);
 }
 
 int fdt_get_mem_rsv(const void *fdt, int n, uint64_t *address, uint64_t *size)