]> git.ipfire.org Git - thirdparty/snort3.git/commitdiff
fixed pattern matcher
authorRuss Combs <rucombs@cisco.com>
Mon, 14 Jul 2014 20:33:42 +0000 (16:33 -0400)
committerRuss Combs <rucombs@cisco.com>
Mon, 14 Jul 2014 20:33:42 +0000 (16:33 -0400)
src/ips_options/ips_content.cc
src/time/profiler.cc
src/utils/boyer_moore.cc

index 1b4a361e235b95dd58d4acf7522e46feda158975..368dbebc9efa9b315a3951052e1c5f45fe615c7a 100644 (file)
@@ -287,13 +287,7 @@ static void validate_content(
 
 static void make_precomp(PatternMatchData * idx)
 {
-    if(idx->skip_stride)
-       free(idx->skip_stride);
-    if(idx->shift_stride)
-       free(idx->shift_stride);
-
     idx->skip_stride = make_skip(idx->pattern_buf, idx->pattern_size);
-
     idx->shift_stride = make_shift(idx->pattern_buf, idx->pattern_size);
 }
 
@@ -482,15 +476,15 @@ static int uniSearchReal(PatternMatchData* pmd, Cursor& c)
             pmd->skip_stride, pmd->shift_stride);
     }
 
-    c.set_delta(pos + pmd->match_delta);
-
     if ( found >= 0 )
     {
-        c.set_pos(pos + found + pmd->pattern_size);
+        int at = pos + found;
+        c.set_delta(at + pmd->match_delta);
+        c.set_pos(at + pmd->pattern_size);
         return 1;
     }
 
-    return 0;
+    return -1;
 }
 
 static int CheckANDPatternMatch(PatternMatchData* idx, Cursor& c)
@@ -708,7 +702,6 @@ static void parse_nocase(
         pmd->pattern_buf[i] = toupper((int)pmd->pattern_buf[i]);
 
     pmd->no_case = 1;
-    make_precomp(pmd);
 }
 
 static void parse_fast_pattern(
@@ -1038,7 +1031,8 @@ static void content_parse(char *rule, PatternMatchData* ds_idx)
 }
 
 static IpsOption* content_ctor(
-    SnortConfig* sc, char *data, OptTreeNode * otn){
+    SnortConfig* sc, char *data, OptTreeNode * otn)
+{
     PatternMatchData *pmd;
     char *data_end;
     char *data_dup;
index bfc13b2b41d10f9b73f6798beabf68da9486dcf6..08630763c919d6013a774d223ae545138cddda6c 100644 (file)
@@ -651,9 +651,8 @@ void RegisterProfile(
     if ( !node->pname && strcasecmp(node->name, TOTAL) )
         node->pname = TOTAL;
 
-    // FIXIT wtf?
-    //if ( !strcasecmp(node->name, "mpse") )
-    //    mpsePerfStats = stats;
+    if ( !strcasecmp(node->name, "mpse") )
+        mpsePerfStats = &node->stats;
 }
 
 void RegisterOtnProfile(const char *keyword, get_profile_func get)
index bdece9e9d6a8ea37907e697bd2a38c97731c388a..7c9067fdca5849ae215e0162dd37263c1047d109 100644 (file)
@@ -181,47 +181,22 @@ int *make_shift(char *ptrn, int plen)
 SO_PUBLIC int mSearch(
     const char *buf, int blen, const char *ptrn, int plen, int *skip, int *shift)
 {
-    int b_idx = plen;
-
-#ifdef DEBUG_MSGS
-    char *hexbuf;
-    int cmpcnt = 0;
-#endif
-
     DEBUG_WRAP(DebugMessage(DEBUG_PATTERN_MATCH,"buf: %p  blen: %d  ptrn: %p  "
                 "plen: %d\n", buf, blen, ptrn, plen););
 
-#ifdef DEBUG_MSGS
-    hexbuf = fasthex((const u_char *)buf, blen);
-    DebugMessage(DEBUG_PATTERN_MATCH,"buf: %s\n", hexbuf);
-    free(hexbuf);
-    hexbuf = fasthex((const u_char *)ptrn, plen);
-    DebugMessage(DEBUG_PATTERN_MATCH,"ptrn: %s\n", hexbuf);
-    free(hexbuf);
-    DebugMessage(DEBUG_PATTERN_MATCH,"buf: %p  blen: %d  ptrn: %p  "
-                 "plen: %d\n", buf, blen, ptrn, plen);
-#endif /* DEBUG_MSGS */
     if(plen == 0)
         return -1;
 
+    int b_idx = plen;
+
     while(b_idx <= blen)
     {
         int p_idx = plen, skip_stride, shift_stride;
 
         while(buf[--b_idx] == ptrn[--p_idx])
         {
-#ifdef DEBUG_MSGS
-            cmpcnt++;
-#endif
-            if(b_idx < 0)
-                return -1;
-
             if(p_idx == 0)
-            {
-                DEBUG_WRAP(DebugMessage(DEBUG_PATTERN_MATCH,
-                            "match: compares = %d.\n", cmpcnt););
                 return b_idx;
-            }
         }
 
         skip_stride = skip[(unsigned char) buf[b_idx]];
@@ -230,9 +205,6 @@ SO_PUBLIC int mSearch(
         b_idx += (skip_stride > shift_stride) ? skip_stride : shift_stride;
     }
 
-    DEBUG_WRAP(DebugMessage(DEBUG_PATTERN_MATCH,
-                "no match: compares = %d.\n", cmpcnt););
-
     return -1;
 }
 
@@ -255,12 +227,10 @@ SO_PUBLIC int mSearch(
  *      -1 if not found or offset >= 0 if found
  *
  ****************************************************************/
-SO_PUBLIC int mSearchCI(const char *buf, int blen, const char *ptrn, int plen, int *skip, int *shift)
+SO_PUBLIC int mSearchCI(
+    const char *buf, int blen, const char *ptrn, int plen, int *skip, int *shift)
 {
     int b_idx = plen;
-#ifdef DEBUG_MSGS
-    int cmpcnt = 0;
-#endif
 
     if(plen == 0)
         return -1;
@@ -269,19 +239,10 @@ SO_PUBLIC int mSearchCI(const char *buf, int blen, const char *ptrn, int plen, i
     {
         int p_idx = plen, skip_stride, shift_stride;
 
-        while((unsigned char) ptrn[--p_idx] ==
-                toupper((unsigned char) buf[--b_idx]))
+        while((unsigned char) ptrn[--p_idx] == toupper((unsigned char) buf[--b_idx]))
         {
-#ifdef DEBUG_MSGS
-            cmpcnt++;
-#endif
             if(p_idx == 0)
-            {
-                DEBUG_WRAP(DebugMessage(DEBUG_PATTERN_MATCH,
-                            "match: compares = %d.\n",
-                            cmpcnt););
                 return b_idx;
-            }
         }
 
         skip_stride = skip[toupper((unsigned char) buf[b_idx])];
@@ -290,8 +251,6 @@ SO_PUBLIC int mSearchCI(const char *buf, int blen, const char *ptrn, int plen, i
         b_idx += (skip_stride > shift_stride) ? skip_stride : shift_stride;
     }
 
-    DEBUG_WRAP(DebugMessage(DEBUG_PATTERN_MATCH, "no match: compares = %d.\n", cmpcnt););
-
     return -1;
 }