Skip to contentSkip to conversation

tool: ifwitool: The function localtime() can return NULL.

PATCH In review Mikhail Ilin 3 participants 3 messages Nov 18, 2022 – Dec 8, 2022

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 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.

---
 tools/ifwitool.c | 2 ++
 1 file changed, 2 insertions(+)
tools/ifwitool.c +2 -0
index 543e9d4e70..b9873deb6b 100644
@@ -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);
 
Signature · 1 line
2.17.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 6 lines · Mikhail Ilin

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.

Quoted 6 lines

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

---
 tools/ifwitool.c | 2 ++
 1 file changed, 2 insertions(+)
#2 lore raw
In reply to Mikhail Ilin
Quoted 9 lines · Mikhail Ilin

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.

Applied to u-boot/next, thanks!

Signature · 1 line
Tom