mirror of
https://github.com/falcosecurity/falco.git
synced 2026-04-25 01:38:00 +00:00
fix(userspace): replace gmtime/localtime with reentrant variants
gmtime() and localtime() return pointers to a shared static buffer, making them unsafe in multi-threaded contexts. Replace all call sites with gmtime_r() and localtime_r() which use caller-provided buffers. Signed-off-by: Leonardo Grasso <me@leonardograsso.com>
This commit is contained in:
@@ -98,7 +98,9 @@ std::string falco_formats::format_event(sinsp_evt *evt,
|
||||
char time_ns[12]; // sizeof ".sssssssssZ"
|
||||
std::string iso8601evttime;
|
||||
|
||||
strftime(time_sec, sizeof(time_sec), "%FT%T", gmtime(&evttime));
|
||||
struct tm tm_buf;
|
||||
gmtime_r(&evttime, &tm_buf);
|
||||
strftime(time_sec, sizeof(time_sec), "%FT%T", &tm_buf);
|
||||
snprintf(time_ns, sizeof(time_ns), ".%09luZ", evt->get_ts() % 1000000000);
|
||||
iso8601evttime = time_sec;
|
||||
iso8601evttime += time_ns;
|
||||
|
||||
Reference in New Issue
Block a user