From: Mike Stepanek (mstepane) Date: Mon, 28 Jan 2019 18:27:14 +0000 (-0500) Subject: Merge pull request #1493 in SNORT/snort3 from ~SMINUT/snort3:ips_file_type to master X-Git-Tag: 3.0.0-251~59 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=7e7d3a535d2d9dee8c570e33f2b33e28afa35206;p=thirdparty%2Fsnort3.git Merge pull request #1493 in SNORT/snort3 from ~SMINUT/snort3:ips_file_type to master Squashed commit of the following: commit 6c2e6330bb957da3783c47a1406ecebb479af7cf Author: Silviu Minut Date: Wed Jan 23 09:25:26 2019 -0500 ips_options: implement FileTypeOption::hash() and FileTypeOption::operator==(), inherited from IpsOption, using the types bitset array, in order to distinguish between different file type options. ips_options: change strncmp to plain strcmp per reviewers' comments. --- diff --git a/src/ips_options/ips_file_type.cc b/src/ips_options/ips_file_type.cc index fc65490dc..9bb160f47 100644 --- a/src/ips_options/ips_file_type.cc +++ b/src/ips_options/ips_file_type.cc @@ -29,6 +29,7 @@ #include "log/messages.h" #include "profiler/profiler.h" #include "protocols/packet.h" +#include "hash/hashfcn.h" using namespace snort; @@ -41,6 +42,9 @@ class FileTypeOption : public IpsOption public: FileTypeOption(FileTypeBitSet&); + uint32_t hash() const override; + bool operator==(const IpsOption& ips) const override; + CursorActionType get_cursor_type() const override { return CAT_NONE; } @@ -58,6 +62,23 @@ FileTypeOption::FileTypeOption(FileTypeBitSet& t) : IpsOption(s_name) types = t; } +uint32_t FileTypeOption::hash() const +{ + uint32_t a = 0, b = 0, c = 0; + mix_str(a, b, c, get_name()); + mix_str(a, b, c, types.to_string().c_str()); + finalize(a, b, c); + return c; +} + +bool FileTypeOption::operator==(const IpsOption& ips) const +{ + if ( strcmp(get_name(), ips.get_name()) ) + return false; + + return types == ((const FileTypeOption&) ips).types; +} + IpsOption::EvalStatus FileTypeOption::eval(Cursor&, Packet* pkt) { Profile profile(fileTypePerfStats); @@ -270,4 +291,3 @@ const BaseApi* ips_file_type[] = &file_type_api.base, nullptr }; -