tool: ifwitool: The function localtime() can return NULL.
authorMikhail Ilin <ilin.mikhail.ol@gmail.com>
Fri, 18 Nov 2022 08:50:02 +0000 (11:50 +0300)
committerTom Rini <trini@konsulko.com>
Thu, 8 Dec 2022 14:25:44 +0000 (09:25 -0500)
This will cause the local_time pointer is passed as the 4th argument
 to function strftime() to also point to NULL. This result in a
 segmentation fault. Thus, it's necessary to add a check of the local_time
 pointer to NULL.

Found by Linux Verification Center (linuxtesting.org) with SVACE.

Signed-off-by: Mikhail Ilin <ilin.mikhail.ol@gmail.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
tools/ifwitool.c

index b2b06cc..a06eb7f 100644 (file)
@@ -1628,6 +1628,8 @@ static void init_manifest_header(struct manifest_header *hdr, size_t size)
 
        curr_time = time(NULL);
        local_time = localtime(&curr_time);
+       assert(local_time != NULL);
+
        strftime(buffer, sizeof(buffer), "0x%Y%m%d", local_time);
        hdr->date = strtoul(buffer, NULL, 16);