]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
pcap-file: fix malformed timestamp crash
authorVictor Julien <victor@inliniac.net>
Tue, 21 Apr 2015 17:29:12 +0000 (19:29 +0200)
committerVictor Julien <victor@inliniac.net>
Wed, 6 May 2015 18:30:06 +0000 (20:30 +0200)
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

index e8f6fe107dbfaa26f2fe30c8e6729a20f8d833e5..1e4237335d522b73b3bd42334ba195d21ed995b9 100644 (file)
@@ -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