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);
}
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)
pmd->pattern_buf[i] = toupper((int)pmd->pattern_buf[i]);
pmd->no_case = 1;
- make_precomp(pmd);
}
static void parse_fast_pattern(
}
static IpsOption* content_ctor(
- SnortConfig* sc, char *data, OptTreeNode * otn){
+ SnortConfig* sc, char *data, OptTreeNode * otn)
+{
PatternMatchData *pmd;
char *data_end;
char *data_dup;
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]];
b_idx += (skip_stride > shift_stride) ? skip_stride : shift_stride;
}
- DEBUG_WRAP(DebugMessage(DEBUG_PATTERN_MATCH,
- "no match: compares = %d.\n", cmpcnt););
-
return -1;
}
* -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;
{
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])];
b_idx += (skip_stride > shift_stride) ? skip_stride : shift_stride;
}
- DEBUG_WRAP(DebugMessage(DEBUG_PATTERN_MATCH, "no match: compares = %d.\n", cmpcnt););
-
return -1;
}