hyperscan: move error logging for hs_compile

Move error logging from util-mpm-hs to reuse it in util-spm-hs as it
has proper hs_compile error handling.

Bug: #8146.
(cherry picked from commit 11073a0190)
pull/14759/head
Sergey Zhidkih 7 months ago committed by Philippe Antoine
parent a25eded66c
commit e7e510dccf

@ -26,6 +26,9 @@
#include "suricata-common.h"
#include "suricata.h"
#include "util-debug.h"
#include "util-mem.h"
#ifdef BUILD_HYPERSCAN
#include "util-hyperscan.h"
@ -56,4 +59,19 @@ char *HSRenderPattern(const uint8_t *pat, uint16_t pat_len)
return str;
}
void HSLogCompileError(const char *expr, hs_compile_error_t *compile_err, hs_error_t err)
{
if (compile_err) {
SCLogError("Unable to compile '%s' with Hyperscan, "
"returned %d."
"Hyperscan compile error: %s",
expr, err, compile_err->message);
hs_free_compile_error(compile_err);
} else {
SCLogError("Unable to compile '%s' with Hyperscan, "
"returned %d.",
expr, err);
}
}
#endif /* BUILD_HYPERSCAN */

@ -26,6 +26,12 @@
#ifndef SURICATA_UTIL_HYPERSCAN__H
#define SURICATA_UTIL_HYPERSCAN__H
#ifdef BUILD_HYPERSCAN
#include <hs.h>
char *HSRenderPattern(const uint8_t *pat, uint16_t pat_len);
void HSLogCompileError(const char *expr, hs_compile_error_t *compile_err, hs_error_t err);
#endif /* BUILD_HYPERSCAN */
#endif /* SURICATA_UTIL_HYPERSCAN__H */

@ -49,8 +49,6 @@
#ifdef BUILD_HYPERSCAN
#include <hs.h>
void SCHSInitCtx(MpmCtx *);
void SCHSInitThreadCtx(MpmCtx *, MpmThreadCtx *);
void SCHSDestroyCtx(MpmCtx *);
@ -607,15 +605,6 @@ static int HSGlobalPatternDatabaseInit(void)
return 0;
}
static void HSLogCompileError(hs_compile_error_t *compile_err)
{
SCLogError("failed to compile hyperscan database");
if (compile_err) {
SCLogError("compile error: %s", compile_err->message);
hs_free_compile_error(compile_err);
}
}
static int HSScratchAlloc(const hs_database_t *db)
{
SCMutexLock(&g_scratch_proto_mutex);
@ -737,7 +726,7 @@ static int PatternDatabaseCompile(PatternDatabase *pd, SCHSCompileData *cd)
(const hs_expr_ext_t *const *)cd->ext, cd->pattern_cnt, HS_MODE_BLOCK, NULL, &pd->hs_db,
&compile_err);
if (err != HS_SUCCESS) {
HSLogCompileError(compile_err);
HSLogCompileError("multiple patterns", compile_err, err);
return -1;
}

@ -32,8 +32,6 @@
#ifdef BUILD_HYPERSCAN
#include <hs.h>
/**
* \internal
* \brief Hyperscan match callback, called by hs_scan.
@ -82,9 +80,7 @@ static int HSBuildDatabase(const uint8_t *needle, uint16_t needle_len,
hs_error_t err = hs_compile(expr, flags, HS_MODE_BLOCK, NULL, &db,
&compile_err);
if (err != HS_SUCCESS) {
SCLogError("Unable to compile '%s' with Hyperscan, "
"returned %d.",
expr, err);
HSLogCompileError(expr, compile_err, err);
return -1;
}

Loading…
Cancel
Save