From dc7715baadf94b370d7737d2581d733ebe2e95a1 Mon Sep 17 00:00:00 2001 From: "Dmitry V. Levin" Date: Sat, 19 Apr 2008 23:45:09 +0000 Subject: [PATCH] 2008-04-19 Dmitry V. Levin * file.c (sprinttime): Check localtime() return value, to avoid potential NULL dereference due to invalid time structures. Signed-off-by: Harald van Dijk Signed-off-by: Mike Frysinger --- ChangeLog | 5 +++++ file.c | 16 +++++++++------- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/ChangeLog b/ChangeLog index c78a5a8f..8fd4063e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,10 @@ 2008-04-19 Dmitry V. Levin + * file.c (sprinttime): Check localtime() return value, to avoid + potential NULL dereference due to invalid time structures. + Signed-off-by: Harald van Dijk + Signed-off-by: Mike Frysinger + * linux/errnoent.h: Update errno list based on latest linux/errno.h and asm-generic/errno*.h files. Signed-off-by: Mike Frysinger diff --git a/file.c b/file.c index a8af0b07..7128523a 100644 --- a/file.c +++ b/file.c @@ -676,20 +676,22 @@ int mode; } static char * -sprinttime(t) -time_t t; +sprinttime(time_t t) { struct tm *tmp; static char buf[32]; if (t == 0) { - sprintf(buf, "0"); + strcpy(buf, "0"); return buf; } - tmp = localtime(&t); - sprintf(buf, "%02d/%02d/%02d-%02d:%02d:%02d", - tmp->tm_year + 1900, tmp->tm_mon + 1, tmp->tm_mday, - tmp->tm_hour, tmp->tm_min, tmp->tm_sec); + if ((tmp = localtime(&t))) + snprintf(buf, sizeof buf, "%02d/%02d/%02d-%02d:%02d:%02d", + tmp->tm_year + 1900, tmp->tm_mon + 1, tmp->tm_mday, + tmp->tm_hour, tmp->tm_min, tmp->tm_sec); + else + snprintf(buf, sizeof buf, "%lu", (unsigned long) t); + return buf; } -- 2.40.0