diff --git a/CHANGES b/CHANGES index 2f4df7415d..185853896d 100644 --- a/CHANGES +++ b/CHANGES @@ -1,4 +1,9 @@ +2.3-599 | 2015-03-25 10:14:57 -0700 + + * Add defensive checks in code to calculate log rotation intervals. + (Pete Nelson). + 2.3-597 | 2015-03-23 12:50:04 -0700 * DTLS analyzer. (Johanna Amann) diff --git a/VERSION b/VERSION index fce1937546..d12f607b2f 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -2.3-597 +2.3-599 diff --git a/src/util.cc b/src/util.cc index ac2a942ed3..501f87e57d 100644 --- a/src/util.cc +++ b/src/util.cc @@ -1352,13 +1352,23 @@ double parse_rotate_base_time(const char* rotate_base_time) double calc_next_rotate(double current, double interval, double base) { + if ( ! interval ) + { + reporter->Error("calc_next_rotate(): interval is zero, falling back to 24hrs"); + interval = 86400; + } + // Calculate start of day. time_t teatime = time_t(current); struct tm t; - t = *localtime_r(&teatime, &t); - t.tm_hour = t.tm_min = t.tm_sec = 0; - double startofday = mktime(&t); + if ( ! localtime_r(&teatime, &t) ) + { + reporter->Error("calc_next_rotate(): failure processing current time (%.6f)", current); + + // fall back to the method used if no base time is given + base = -1; + } if ( base < 0 ) // No base time given. To get nice timestamps, we round @@ -1366,6 +1376,9 @@ double calc_next_rotate(double current, double interval, double base) return floor(current / interval) * interval + interval - current; + t.tm_hour = t.tm_min = t.tm_sec = 0; + double startofday = mktime(&t); + // current < startofday + base + i * interval <= current + interval return startofday + base + ceil((current - startofday - base) / interval) * interval -