2008-04-19 Dmitry V. Levin <ldv@altlinux.org>
* file.c (sprinttime): Check localtime() return value, to avoid
potential NULL dereference due to invalid time structures.
Signed-off-by: Harald van Dijk <truedfx@gentoo.org>
Signed-off-by: Mike Frysinger <vapier@gentoo.org>
diff --git a/ChangeLog b/ChangeLog
index c78a5a8..8fd4063 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,10 @@
2008-04-19 Dmitry V. Levin <ldv@altlinux.org>
+ * file.c (sprinttime): Check localtime() return value, to avoid
+ potential NULL dereference due to invalid time structures.
+ Signed-off-by: Harald van Dijk <truedfx@gentoo.org>
+ Signed-off-by: Mike Frysinger <vapier@gentoo.org>
+
* linux/errnoent.h: Update errno list based on latest
linux/errno.h and asm-generic/errno*.h files.
Signed-off-by: Mike Frysinger <vapier@gentoo.org>
diff --git a/file.c b/file.c
index a8af0b0..7128523 100644
--- a/file.c
+++ b/file.c
@@ -676,20 +676,22 @@
}
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;
}