From 5bc8fcca083c0be1c93927012e219341cb1aebc5 Mon Sep 17 00:00:00 2001 From: Nick Banks Date: Fri, 27 Dec 2024 13:34:27 -0600 Subject: [PATCH 1/2] Fix code scanning alert no. 213: Use of potentially dangerous function Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com> --- src/quicreach.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/quicreach.cpp b/src/quicreach.cpp index 4f0fd99..1609fcc 100644 --- a/src/quicreach.cpp +++ b/src/quicreach.cpp @@ -329,8 +329,9 @@ void DumpResultsToFile() { } char UtcDateTime[256]; time_t Time = time(nullptr); - struct tm* Tm = gmtime(&Time); - strftime(UtcDateTime, sizeof(UtcDateTime), "%Y.%m.%d-%H:%M:%S", Tm); + struct tm Tm; + gmtime_r(&Time, &Tm); + strftime(UtcDateTime, sizeof(UtcDateTime), "%Y.%m.%d-%H:%M:%S", &Tm); fprintf(File, "%s,%u,%u,%u,%u,%u,%u,%u,%u\n", UtcDateTime, Results.TotalCount.load(), Results.ReachableCount.load(), Results.TooMuchCount.load(), Results.MultiRttCount.load(), Results.RetryCount.load(), Results.IPv6Count.load(), Results.Quicv2Count.load(), Results.WayTooMuchCount.load()); From 9836bb2ed0ab08e04f2022c729e359dc001ba6a6 Mon Sep 17 00:00:00 2001 From: Nick Banks Date: Mon, 30 Dec 2024 12:21:23 -0500 Subject: [PATCH 2/2] Fix Windows build --- src/quicreach.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/quicreach.cpp b/src/quicreach.cpp index 1609fcc..8183fbd 100644 --- a/src/quicreach.cpp +++ b/src/quicreach.cpp @@ -330,7 +330,11 @@ void DumpResultsToFile() { char UtcDateTime[256]; time_t Time = time(nullptr); struct tm Tm; +#ifdef _WIN32 + gmtime_s(&Tm, &Time); +#else gmtime_r(&Time, &Tm); +#endif strftime(UtcDateTime, sizeof(UtcDateTime), "%Y.%m.%d-%H:%M:%S", &Tm); fprintf(File, "%s,%u,%u,%u,%u,%u,%u,%u,%u\n", UtcDateTime, Results.TotalCount.load(), Results.ReachableCount.load(), Results.TooMuchCount.load(), Results.MultiRttCount.load(),