Skip to content

Commit

Permalink
fix(userspace/libsinsp): zero-init time before string parsing
Browse files Browse the repository at this point in the history
Signed-off-by: Jason Dellaluce <jasondellaluce@gmail.com>
  • Loading branch information
jasondellaluce authored and poiana committed Dec 2, 2023
1 parent 33c87ad commit 1aad982
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions userspace/libsinsp/utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1080,7 +1080,7 @@ void sinsp_utils::ts_to_iso_8601(uint64_t ts, OUT std::string* res)
bool sinsp_utils::parse_iso_8601_utc_string(const std::string& time_str, uint64_t &ns)
{
#ifndef _WIN32
tm tm_time;
tm tm_time{0};
char* rem = strptime(time_str.c_str(), "%Y-%m-%dT%H:%M:", &tm_time);
if(rem == NULL || *rem == '\0')
{
Expand Down Expand Up @@ -1112,7 +1112,7 @@ time_t get_epoch_utc_seconds(const std::string& time_str, const std::string& fmt
{
throw sinsp_exception("get_epoch_utc_seconds(): empty time or format string.");
}
tm tm_time;
tm tm_time{0};
strptime(time_str.c_str(), fmt.c_str(), &tm_time);
tm_time.tm_isdst = -1; // strptime does not set this, signal timegm to determine DST
return timegm(&tm_time);
Expand Down

0 comments on commit 1aad982

Please sign in to comment.