]> git.ipfire.org Git - thirdparty/snort3.git/commitdiff
Merge pull request #2060 in SNORT/snort3 from ~SHEFAPRA/snort3:fix_gmtime to master
authorSteve Chew (stechew) <stechew@cisco.com>
Fri, 6 Mar 2020 21:06:48 +0000 (21:06 +0000)
committerSteve Chew (stechew) <stechew@cisco.com>
Fri, 6 Mar 2020 21:06:48 +0000 (21:06 +0000)
Squashed commit of the following:

commit d65d98524cbe1485686934992791fec0d16d4b9f
Author: Shefali <shefapra@cisco.com>
Date:   Wed Mar 4 12:28:39 2020 -0500

    util: handled out-of-range time

src/utils/util.cc

index 55d93f9ecef3c8682ec79e3578a25c35860b3ba0..905fa6f9f862a697d2f62fc89024cc09145d98f9 100644 (file)
@@ -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