aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authoremanuele-f <black.silver@hotmail.it>2019-10-02 16:26:52 +0200
committeremanuele-f <black.silver@hotmail.it>2019-10-02 16:26:52 +0200
commit7f510c10fe1f764bf42417110cd53cf6ac765a4b (patch)
tree14ec089325a394a5e346ee987385545cae7286be /src
parenta559ba20b1e1c4554c9abb4dc962ef122416c5c2 (diff)
Fix double free after b19bfa1e207a8d4972bfc701fde5d5c014f95383
Diffstat (limited to 'src')
-rw-r--r--src/lib/third_party/include/actypes.h1
-rw-r--r--src/lib/third_party/include/node.h2
-rw-r--r--src/lib/third_party/src/ahocorasick.c4
-rw-r--r--src/lib/third_party/src/node.c9
4 files changed, 10 insertions, 6 deletions
diff --git a/src/lib/third_party/include/actypes.h b/src/lib/third_party/include/actypes.h
index 5a94b63a1..2308cd686 100644
--- a/src/lib/third_party/include/actypes.h
+++ b/src/lib/third_party/include/actypes.h
@@ -63,6 +63,7 @@ typedef struct
{
AC_ALPHABET_t * astring; /* String of alphabets */
unsigned int length; /* Length of pattern */
+ u_int8_t is_existing; /* 1 if the node is already part of another AC_PATTERN_t */
AC_REP_t rep; /* Representative string (optional) */
} AC_PATTERN_t;
diff --git a/src/lib/third_party/include/node.h b/src/lib/third_party/include/node.h
index 30836df6a..c172112aa 100644
--- a/src/lib/third_party/include/node.h
+++ b/src/lib/third_party/include/node.h
@@ -55,7 +55,7 @@ struct edge
AC_NODE_t * node_create (void);
AC_NODE_t * node_create_next (AC_NODE_t * thiz, AC_ALPHABET_t alpha);
-void node_register_matchstr (AC_NODE_t * thiz, AC_PATTERN_t * str);
+void node_register_matchstr (AC_NODE_t * thiz, AC_PATTERN_t * str, u_int8_t is_existing);
void node_register_outgoing (AC_NODE_t * thiz, AC_NODE_t * next, AC_ALPHABET_t alpha);
AC_NODE_t * node_find_next (AC_NODE_t * thiz, AC_ALPHABET_t alpha);
AC_NODE_t * node_findbs_next (AC_NODE_t * thiz, AC_ALPHABET_t alpha);
diff --git a/src/lib/third_party/src/ahocorasick.c b/src/lib/third_party/src/ahocorasick.c
index db398cfcd..ffa8bac77 100644
--- a/src/lib/third_party/src/ahocorasick.c
+++ b/src/lib/third_party/src/ahocorasick.c
@@ -108,7 +108,7 @@ AC_ERROR_t ac_automata_add (AC_AUTOMATA_t * thiz, AC_PATTERN_t * patt)
return ACERR_DUPLICATE_PATTERN;
n->final = 1;
- node_register_matchstr(n, patt);
+ node_register_matchstr(n, patt, 0);
thiz->total_patterns++;
return ACERR_SUCCESS;
@@ -327,7 +327,7 @@ static void ac_automata_union_matchstrs (AC_NODE_t * node)
while ((m = m->failure_node))
{
for (i=0; i < m->matched_patterns_num; i++)
- node_register_matchstr(node, &(m->matched_patterns[i]));
+ node_register_matchstr(node, &(m->matched_patterns[i]), 1 /* this is an existing node */);
if (m->final)
node->final = 1;
diff --git a/src/lib/third_party/src/node.c b/src/lib/third_party/src/node.c
index 3eda50461..96e25e8af 100644
--- a/src/lib/third_party/src/node.c
+++ b/src/lib/third_party/src/node.c
@@ -76,8 +76,10 @@ void node_init(AC_NODE_t * thiz)
void node_release(AC_NODE_t * thiz, u_int8_t free_pattern)
{
if(free_pattern) {
- for(int i=0; i<thiz->matched_patterns_num; i++)
- ndpi_free(thiz->matched_patterns[i].astring);
+ for(int i=0; i<thiz->matched_patterns_num; i++) {
+ if(!thiz->matched_patterns[i].is_existing)
+ ndpi_free(thiz->matched_patterns[i].astring);
+ }
}
ndpi_free(thiz->matched_patterns);
@@ -179,7 +181,7 @@ AC_NODE_t * node_create_next (AC_NODE_t * thiz, AC_ALPHABET_t alpha)
* FUNCTION: node_register_matchstr
* Adds the pattern to the list of accepted pattern.
******************************************************************************/
-void node_register_matchstr (AC_NODE_t * thiz, AC_PATTERN_t * str)
+void node_register_matchstr (AC_NODE_t * thiz, AC_PATTERN_t * str, u_int8_t is_existing)
{
/* Check if the new pattern already exists in the node list */
if (node_has_matchstr(thiz, str))
@@ -197,6 +199,7 @@ void node_register_matchstr (AC_NODE_t * thiz, AC_PATTERN_t * str)
thiz->matched_patterns[thiz->matched_patterns_num].astring = str->astring;
thiz->matched_patterns[thiz->matched_patterns_num].length = str->length;
+ thiz->matched_patterns[thiz->matched_patterns_num].is_existing = is_existing;
memcpy(&thiz->matched_patterns[thiz->matched_patterns_num].rep, &str->rep, sizeof(AC_REP_t));
thiz->matched_patterns_num++;
}