From: Victor Julien Date: Tue, 21 Apr 2015 17:29:12 +0000 (+0200) Subject: pcap-file: fix malformed timestamp crash X-Git-Tag: suricata-2.1beta4~27 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=a4a1c396e1595ebf5b86a2dd1bedbe604584e7ea;p=thirdparty%2Fsuricata.git 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 --- 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