From a4a1c396e1595ebf5b86a2dd1bedbe604584e7ea Mon Sep 17 00:00:00 2001 From: Victor Julien Date: Tue, 21 Apr 2015 19:29:12 +0200 Subject: [PATCH] pcap-file: fix malformed timestamp crash A bad timestamp would lead to SCLocalTime returning NULL. This case wasn't checked, leading to a NULL deref. Reported-by: Kostya Kortchinsky of the Google Security Team --- src/util-time.c | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/src/util-time.c b/src/util-time.c index e8f6fe107d..1e4237335d 100644 --- a/src/util-time.c +++ b/src/util-time.c @@ -129,9 +129,13 @@ void CreateIsoTimeString (const struct timeval *ts, char *str, size_t size) struct tm local_tm; struct tm *t = (struct tm*)SCLocalTime(time, &local_tm); - snprintf(str, size, "%04d-%02d-%02dT%02d:%02d:%02d.%06u", - t->tm_year + 1900, t->tm_mon + 1, t->tm_mday, t->tm_hour, - t->tm_min, t->tm_sec, (uint32_t) ts->tv_usec); + if (likely(t != NULL)) { + snprintf(str, size, "%04d-%02d-%02dT%02d:%02d:%02d.%06u", + t->tm_year + 1900, t->tm_mon + 1, t->tm_mday, t->tm_hour, + t->tm_min, t->tm_sec, (uint32_t) ts->tv_usec); + } else { + snprintf(str, size, "ts-error"); + } } /* @@ -152,9 +156,13 @@ void CreateTimeString (const struct timeval *ts, char *str, size_t size) struct tm local_tm; struct tm *t = (struct tm*)SCLocalTime(time, &local_tm); - snprintf(str, size, "%02d/%02d/%02d-%02d:%02d:%02d.%06u", - t->tm_mon + 1, t->tm_mday, t->tm_year + 1900, t->tm_hour, - t->tm_min, t->tm_sec, (uint32_t) ts->tv_usec); + if (likely(t != NULL)) { + snprintf(str, size, "%02d/%02d/%02d-%02d:%02d:%02d.%06u", + t->tm_mon + 1, t->tm_mday, t->tm_year + 1900, t->tm_hour, + t->tm_min, t->tm_sec, (uint32_t) ts->tv_usec); + } else { + snprintf(str, size, "ts-error"); + } } #else