]> git.ipfire.org Git - thirdparty/snort3.git/commitdiff
Merge pull request #1896 in SNORT/snort3 from ~RJAVALI/snort3:GRE_issu to master
authorGeorge Koikara (gkoikara) <gkoikara@cisco.com>
Thu, 19 Dec 2019 12:24:01 +0000 (12:24 +0000)
committerGeorge Koikara (gkoikara) <gkoikara@cisco.com>
Thu, 19 Dec 2019 12:24:01 +0000 (12:24 +0000)
Squashed commit of the following:

commit a50900239a95fe36fb81a608a4e13068a42a0be5
Author: Raghavendra Javali <rjavali@cisco.com>
Date:   Thu Dec 12 05:23:19 2019 -0500

    codec: Header files alphabetically re-ordered and addition of unit test case for code coverage.

src/codecs/ip/cd_gre.cc

index 9c6d62aa910ba23038b153627754b42ae2cc6c22..1921ec7a56639bbd4c689be1774d7bb1f0e96026 100644 (file)
 
 #include "codecs/codec_module.h"
 #include "framework/codec.h"
+#include "log/messages.h"
 #include "log/text_log.h"
 #include "main/snort_config.h"
 #include "protocols/gre.h"
-#include "log/messages.h"
+
+#ifdef UNIT_TEST
+#include "catch/snort_catch.h"
+#endif
 
 using namespace snort;
 
@@ -298,3 +302,23 @@ const BaseApi* cd_gre[] =
     nullptr
 };
 
+//--------------------------------------------------------------------------
+// unit tests
+//--------------------------------------------------------------------------
+
+#ifdef UNIT_TEST
+TEST_CASE ("Validate error check for raw_len greater than GRE_HEADER_LEN", "[cd_gre]")
+{
+    GreCodec grecodec;
+    const uint8_t raw_in = 0;
+    uint8_t raw_len = GRE_HEADER_LEN + 1;
+    ip::IpApi ip_api;
+    EncState enc(ip_api, ENC_FLAG_VAL, IpProtocol::GRE, 0, 0);
+    uint16_t size = 1;
+    uint8_t t = 0;
+    Buffer buf(&t, size);
+    Flow *flow = NULL;
+
+    CHECK (grecodec.encode(&raw_in,raw_len,enc,buf,flow) == false);
+}
+#endif