diff options
author | Luca Deri <deri@ntop.org> | 2018-05-29 22:50:18 +0200 |
---|---|---|
committer | Luca Deri <deri@ntop.org> | 2018-05-29 22:50:18 +0200 |
commit | 6b16ad709ee4ef7c504650cf9d4efdf7e56c517b (patch) | |
tree | 492969a1c4069a9a135d300e005bc809fa250993 /src | |
parent | 3407db11cdcb356c325c827069f5acb51598bef3 (diff) |
Fix for #560
Diffstat (limited to 'src')
-rw-r--r-- | src/lib/ndpi_main.c | 9 | ||||
-rw-r--r-- | src/lib/third_party/include/actypes.h | 2 | ||||
-rw-r--r-- | src/lib/third_party/src/ahocorasick.c | 5 |
3 files changed, 9 insertions, 7 deletions
diff --git a/src/lib/ndpi_main.c b/src/lib/ndpi_main.c index aaa1109e9..5f1f9800d 100644 --- a/src/lib/ndpi_main.c +++ b/src/lib/ndpi_main.c @@ -1883,9 +1883,9 @@ static void ndpi_init_protocol_defaults(struct ndpi_detection_module_struct *ndp /* ****************************************************** */ -static int ac_match_handler(AC_MATCH_t *m, void *param) { +static int ac_match_handler(AC_MATCH_t *m, AC_TEXT_t *txt, void *param) { int *matching_protocol_id = (int*)param; - + int min_len = (txt->length < m->patterns->length) ? txt->length : m->patterns->length; /* Return 1 for stopping to the first match. We might consider searching for the more @@ -1893,7 +1893,10 @@ static int ac_match_handler(AC_MATCH_t *m, void *param) { */ *matching_protocol_id = m->patterns[0].rep.number; - return 0; /* 0 to continue searching, !0 to stop */ + if(strncmp(txt->astring, m->patterns->astring, min_len) == 0) + return(1); /* If the pattern found matches the string at the beginning we stop here */ + else + return 0; /* 0 to continue searching, !0 to stop */ } /* ******************************************************************** */ diff --git a/src/lib/third_party/include/actypes.h b/src/lib/third_party/include/actypes.h index 1900ae9a0..807e5026a 100644 --- a/src/lib/third_party/include/actypes.h +++ b/src/lib/third_party/include/actypes.h @@ -125,7 +125,7 @@ typedef enum * continue searching, otherwise it will return from ac_automata_search() * to your calling function. **/ -typedef int (*MATCH_CALBACK_f)(AC_MATCH_t *, void *); +typedef int (*MATCH_CALBACK_f)(AC_MATCH_t *, AC_TEXT_t *, void *); /* AC_PATTRN_MAX_LENGTH: * Maximum acceptable pattern length in AC_PATTERN_t.length diff --git a/src/lib/third_party/src/ahocorasick.c b/src/lib/third_party/src/ahocorasick.c index ce064033f..fd6541dd7 100644 --- a/src/lib/third_party/src/ahocorasick.c +++ b/src/lib/third_party/src/ahocorasick.c @@ -189,16 +189,15 @@ int ac_automata_search (AC_AUTOMATA_t * thiz, AC_TEXT_t * txt, void * param) position++; } - if(curr->final && next) + if(curr->final && next) { /* We check 'next' to find out if we came here after a alphabet * transition or due to a fail. in second case we should not report * matching because it was reported in previous node */ - { thiz->match.position = position + thiz->base_position; thiz->match.match_num = curr->matched_patterns_num; thiz->match.patterns = curr->matched_patterns; /* we found a match! do call-back */ - if (thiz->match_callback(&thiz->match, param)) + if (thiz->match_callback(&thiz->match, txt, param)) return 1; } } |