From 89ccdaf32bcde0ccd5855189f9749f488ce91030 Mon Sep 17 00:00:00 2001 From: "Steve Chew (stechew)" Date: Fri, 6 Mar 2020 21:06:48 +0000 Subject: [PATCH] Merge pull request #2060 in SNORT/snort3 from ~SHEFAPRA/snort3:fix_gmtime to master Squashed commit of the following: commit d65d98524cbe1485686934992791fec0d16d4b9f Author: Shefali Date: Wed Mar 4 12:28:39 2020 -0500 util: handled out-of-range time --- src/utils/util.cc | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/utils/util.cc b/src/utils/util.cc index 55d93f9ec..905fa6f9f 100644 --- a/src/utils/util.cc +++ b/src/utils/util.cc @@ -63,6 +63,10 @@ extern "C" { #include "util_cstring.h" +#ifdef UNIT_TEST +#include "catch/snort_catch.h" +#endif + using namespace snort; /**************************************************************************** @@ -211,7 +215,9 @@ int gmt2local(time_t t) t = time(nullptr); struct tm gmt; - gmtime_r(&t, &gmt); + struct tm* lt = gmtime_r(&t, &gmt); + if (lt == nullptr) + return 0; struct tm loc; localtime_r(&t, &loc); @@ -634,4 +640,9 @@ char* snort_strdup(const char* str) } - +#ifdef UNIT_TEST +TEST_CASE("gmt2local_time_out_of_range", "[util]") +{ + REQUIRE((gmt2local(0xffffffff1fff2f)==0)); +} +#endif -- 2.47.3