From: George Koikara (gkoikara) Date: Thu, 19 Dec 2019 12:24:01 +0000 (+0000) Subject: Merge pull request #1896 in SNORT/snort3 from ~RJAVALI/snort3:GRE_issu to master X-Git-Tag: 3.0.0-267~2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=41dc97a4ce6127605a36cfb6ff9e806702e318a2;p=thirdparty%2Fsnort3.git Merge pull request #1896 in SNORT/snort3 from ~RJAVALI/snort3:GRE_issu to master Squashed commit of the following: commit a50900239a95fe36fb81a608a4e13068a42a0be5 Author: Raghavendra Javali Date: Thu Dec 12 05:23:19 2019 -0500 codec: Header files alphabetically re-ordered and addition of unit test case for code coverage. --- diff --git a/src/codecs/ip/cd_gre.cc b/src/codecs/ip/cd_gre.cc index 9c6d62aa9..1921ec7a5 100644 --- a/src/codecs/ip/cd_gre.cc +++ b/src/codecs/ip/cd_gre.cc @@ -24,10 +24,14 @@ #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