From a765cfde191aaa37b797d8579d523a45a9fe5895 Mon Sep 17 00:00:00 2001 From: Justin Viiret Date: Mon, 23 May 2016 14:06:00 +1000 Subject: [PATCH] mpm-hs,spm-hs: don't call hs_scan() for zero bytes --- src/util-mpm-hs.c | 4 ++++ src/util-spm-hs.c | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/src/util-mpm-hs.c b/src/util-mpm-hs.c index 8b993ae160..ae0de5e0a9 100644 --- a/src/util-mpm-hs.c +++ b/src/util-mpm-hs.c @@ -919,6 +919,10 @@ uint32_t SCHSSearch(const MpmCtx *mpm_ctx, MpmThreadCtx *mpm_thread_ctx, SCHSThreadCtx *hs_thread_ctx = (SCHSThreadCtx *)(mpm_thread_ctx->ctx); const PatternDatabase *pd = ctx->pattern_db; + if (unlikely(buflen == 0)) { + return 0; + } + SCHSCallbackCtx cctx = {.ctx = ctx, .pmq = pmq, .match_count = 0}; /* scratch should have been cloned from g_scratch_proto at thread init. */ diff --git a/src/util-spm-hs.c b/src/util-spm-hs.c index 5ca0d333d0..898b6e9067 100644 --- a/src/util-spm-hs.c +++ b/src/util-spm-hs.c @@ -141,6 +141,10 @@ static uint8_t *HSScan(const SpmCtx *ctx, SpmThreadCtx *thread_ctx, const SpmHsCtx *sctx = ctx->ctx; hs_scratch_t *scratch = thread_ctx->ctx; + if (unlikely(haystack_len == 0)) { + return NULL; + } + uint64_t match_offset = UINT64_MAX; hs_error_t err = hs_scan(sctx->db, (const char *)haystack, haystack_len, 0, scratch, MatchEvent, &match_offset); -- 2.47.2