[PATCH v2020.01] tool: ifwitool: The function localtime() can return NULL.

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 --- tools/ifwitool.c | 2 ++ 1 file changed, 2 insertions(+)
diff --git a/tools/ifwitool.c b/tools/ifwitool.c index 543e9d4e70..b9873deb6b 100644 --- a/tools/ifwitool.c +++ b/tools/ifwitool.c @@ -1630,6 +1630,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);

On Fri, 18 Nov 2022 at 05:36, Mikhail Ilin ilin.mikhail.ol@gmail.com wrote:
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
tools/ifwitool.c | 2 ++ 1 file changed, 2 insertions(+)
Reviewed-by: Simon Glass sjg@chromium.org

On Fri, Nov 18, 2022 at 11:50:02AM +0300, Mikhail Ilin wrote:
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
Applied to u-boot/next, thanks!
participants (3)
-
Mikhail Ilin
-
Simon Glass
-
Tom Rini