mirror of
https://github.com/zeek/zeek.git
synced 2025-10-02 14:48:21 +00:00
Add defensive check for localtime_r() call
This commit is contained in:
parent
5e2defebe5
commit
3ef2cd70a4
1 changed files with 9 additions and 3 deletions
12
src/util.cc
12
src/util.cc
|
@ -1356,9 +1356,13 @@ double calc_next_rotate(double current, double interval, double base)
|
|||
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(): can't parse current time");
|
||||
|
||||
// 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
|
||||
|
@ -1367,6 +1371,8 @@ double calc_next_rotate(double current, double interval, double base)
|
|||
+ interval - current;
|
||||
|
||||
// current < startofday + base + i * interval <= current + interval
|
||||
t.tm_hour = t.tm_min = t.tm_sec = 0;
|
||||
double startofday = mktime(&t);
|
||||
return startofday + base +
|
||||
ceil((current - startofday - base) / interval) * interval -
|
||||
current;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue