Merge branch 'topic/petiepooo/localtime_r-segv' of https://github.com/petiepooo/bro

Added one more failure check for a zero interval.
This commit is contained in:
Robin Sommer 2015-03-25 10:14:57 -07:00
commit b4c0f217c0
3 changed files with 22 additions and 4 deletions

View file

@ -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 -