]> git.ipfire.org Git - thirdparty/snort3.git/commitdiff
hyperscan: add warning when deserialization fails that includes error code
authorruss <rucombs@cisco.com>
Wed, 27 Jul 2022 18:05:53 +0000 (14:05 -0400)
committerRuss Combs (rucombs) <rucombs@cisco.com>
Sat, 13 Aug 2022 18:39:08 +0000 (18:39 +0000)
src/search_engines/hyperscan.cc
src/search_engines/test/mpse_test_stubs.cc

index e01e5d560cd7acc8a54e22de2b07d3365d70e1ee..5e5b043466d6039a66570f3e2bdd6c3bfff257f7 100644 (file)
@@ -205,8 +205,11 @@ bool HyperscanMpse::serialize(uint8_t*& buf, size_t& sz) const
 
 bool HyperscanMpse::deserialize(const uint8_t* buf, size_t sz)
 {
-    if ( hs_deserialize_database((const char*)buf, sz, &hs_db) != HS_SUCCESS or !hs_db )
+    if ( hs_error_t err = hs_deserialize_database((const char*)buf, sz, &hs_db) )
+    {
+        ParseWarning(WARN_RULES, "can't deserialize hyperscan database (%d)", err);
         return false;
+    }
 
     if ( hs_error_t err = hs_alloc_scratch(hs_db, &s_scratch[get_instance_id()]) )
     {
@@ -288,8 +291,15 @@ int HyperscanMpse::prep_patterns(SnortConfig* sc)
         ids.emplace_back(id++);
     }
 
+#ifdef REG_TEST
+    hs_platform_info_t info = { HS_TUNE_FAMILY_SNB, 0, 0, 0 };
+    auto pinfo = &info;
+#else
+    hs_platform_info_t* pinfo = nullptr;
+#endif
+
     if ( hs_compile_multi(&pats[0], &flags[0], &ids[0], pvector.size(), HS_MODE_BLOCK,
-            nullptr, &hs_db, &errptr) or !hs_db )
+        pinfo, &hs_db, &errptr) or !hs_db )
     {
         ParseError("can't compile hyperscan pattern database: %s (%d) - '%s'",
             errptr->message, errptr->expression,
index eb24185eb95af121efe45a0f74836e1705ff79f4..b4eca2bb178e167dfc7d0b276f30572bb09b314f 100644 (file)
@@ -30,6 +30,7 @@
 #include "framework/base_api.h"
 #include "framework/mpse.h"
 #include "framework/mpse_batch.h"
+#include "log/messages.h"
 #include "main/snort_config.h"
 #include "managers/mpse_manager.h"
 #include "search_engines/pat_stats.h"
@@ -89,7 +90,10 @@ void ErrorMessage(const char*, ...) { }
 
 void LogValue(const char*, const char*, FILE*) { }
 void LogMessage(const char*, ...) { }
+void ParseWarning(WarningGroup, const char*, ...) { }
+
 [[noreturn]] void FatalError(const char*,...) { exit(1); }
+
 void LogCount(char const*, uint64_t, FILE*) { }
 void LogStat(const char*, double, FILE*) { }