]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
mpm/ac-ks: apply offset/depth
authorVictor Julien <victor@inliniac.net>
Mon, 6 Nov 2017 13:41:39 +0000 (14:41 +0100)
committerVictor Julien <victor@inliniac.net>
Mon, 11 Dec 2017 15:59:11 +0000 (16:59 +0100)
src/util-mpm-ac-tile.c
src/util-mpm-ac-tile.h

index f1ff27511a47ac21a9d64e09d189fb681254c84e..07d791ad1a878598900a684b23c668a32702a105 100644 (file)
@@ -946,6 +946,8 @@ int SCACTilePreparePatterns(MpmCtx *mpm_ctx)
             ctx->pattern_list[i].patlen = len;
             string_space += space;
         }
+        ctx->pattern_list[i].offset = ctx->parray[i]->offset;
+        ctx->pattern_list[i].depth = ctx->parray[i]->depth;
         ctx->pattern_list[i].pid = ctx->parray[i]->id;
 
         /* ACPatternList now owns this memory */
@@ -1177,7 +1179,7 @@ static int CheckMatch(const SCACTileSearchCtx *ctx, PrefilterRuleStore *pmq,
                uint16_t state, int i, int matches,
                uint8_t *mpm_bitarray)
 {
-    SCACTilePatternList *pattern_list = ctx->pattern_list;
+    const SCACTilePatternList *pattern_list = ctx->pattern_list;
     const uint8_t *buf_offset = buf + i + 1; // Lift out of loop
     uint32_t no_of_entries = ctx->output_table[state].no_of_entries;
     MpmPatternIndex *patterns = ctx->output_table[state].patterns;
@@ -1196,13 +1198,18 @@ static int CheckMatch(const SCACTileSearchCtx *ctx, PrefilterRuleStore *pmq,
             matches++;
             continue;
         }
+        const SCACTilePatternList *pat = &pattern_list[pindex];
+        const int offset = i - pat->patlen + 1;
+        if (offset < (int)pat->offset || (pat->depth && i > pat->depth))
+            continue;
+
         /* Double check case-sensitve match now. */
         if (patterns[k] >> 31) {
-            uint16_t patlen = pattern_list[pindex].patlen;
+            const uint16_t patlen = pat->patlen;
 #ifdef __tile__
-            if (SCMemcmpNZ(pattern_list[pindex].cs, buf_offset - patlen, patlen) != 0) {
+            if (SCMemcmpNZ(pat->cs, buf_offset - patlen, patlen) != 0) {
 #else
-            if (SCMemcmp(pattern_list[pindex].cs, buf_offset - patlen, patlen) != 0) {
+            if (SCMemcmp(pat->cs, buf_offset - patlen, patlen) != 0) {
 #endif
                 /* Case-sensitive match failed. */
                 continue;
index a53ae4f368982a4530811f9d79b66b8ffe4341e4..5e3b166f1c4135a589e0290f94ab33b2c0a3290d 100644 (file)
@@ -30,6 +30,9 @@ typedef struct SCACTilePatternList_ {
     uint8_t *cs;
     uint16_t patlen;
 
+    uint16_t offset;
+    uint16_t depth;
+
     /* Pattern Id */
     uint32_t pid;