Call ac_automata_release with free_pattern = 1 (malloc'ed patterns expected in ndpi_add_string_to_automa)

This commit is contained in:
Alfredo Cardigliano
2021-06-14 14:41:14 +02:00
parent 380286c069
commit 4aefbe0c7a
3 changed files with 10 additions and 7 deletions
+2 -2
View File
@@ -3693,8 +3693,8 @@ void automataUnitTest() {
void *automa = ndpi_init_automa(); void *automa = ndpi_init_automa();
assert(automa); assert(automa);
assert(ndpi_add_string_to_automa(automa, "hello") == 0); assert(ndpi_add_string_to_automa(automa, strdup("hello")) == 0);
assert(ndpi_add_string_to_automa(automa, "world") == 0); assert(ndpi_add_string_to_automa(automa, strdup("world")) == 0);
ndpi_finalize_automa(automa); ndpi_finalize_automa(automa);
assert(ndpi_match_string(automa, "This is the wonderful world of nDPI") == 1); assert(ndpi_match_string(automa, "This is the wonderful world of nDPI") == 1);
ndpi_free_automa(automa); ndpi_free_automa(automa);
+2 -2
View File
@@ -840,7 +840,7 @@ extern "C" {
* Add a string to match to an automata * Add a string to match to an automata
* *
* @par The automata initialized with ndpi_init_automa(); * @par The automata initialized with ndpi_init_automa();
* @par The (sub)string to search * @par The (sub)string to search (malloc'ed memory)
* @par The number associated with this string * @par The number associated with this string
* @return 0 in case of no error, or -1 if an error occurred. * @return 0 in case of no error, or -1 if an error occurred.
* *
@@ -851,7 +851,7 @@ extern "C" {
* Add a string to match to an automata. Same as ndpi_add_string_value_to_automa() with num set to 1 * Add a string to match to an automata. Same as ndpi_add_string_value_to_automa() with num set to 1
* *
* @par The automata initialized with ndpi_init_automa(); * @par The automata initialized with ndpi_init_automa();
* @par The (sub)string to search * @par The (sub)string to search (malloc'ed memory)
* @return 0 in case of no error, or -1 if an error occurred. * @return 0 in case of no error, or -1 if an error occurred.
* *
*/ */
+5 -2
View File
@@ -701,15 +701,18 @@ static void init_string_based_protocols(struct ndpi_detection_module_struct *ndp
/* ************************ */ /* ************************ */
for(i = 0; tls_certificate_match[i].string_to_match != NULL; i++) { for(i = 0; tls_certificate_match[i].string_to_match != NULL; i++) {
#if 0 #if 0
printf("%s() %s / %u\n", __FUNCTION__, printf("%s() %s / %u\n", __FUNCTION__,
tls_certificate_match[i].string_to_match, tls_certificate_match[i].string_to_match,
tls_certificate_match[i].protocol_id); tls_certificate_match[i].protocol_id);
#endif #endif
/* Note: string_to_match is not malloc'ed here as ac_automata_release is
* called with free_pattern = 0 */
ndpi_add_string_value_to_automa(ndpi_str->tls_cert_subject_automa.ac_automa, ndpi_add_string_value_to_automa(ndpi_str->tls_cert_subject_automa.ac_automa,
tls_certificate_match[i].string_to_match, tls_certificate_match[i].string_to_match,
tls_certificate_match[i].protocol_id); tls_certificate_match[i].protocol_id);
} }
/* ************************ */ /* ************************ */
@@ -2427,7 +2430,7 @@ int ndpi_add_string_to_automa(void *_automa, char *str) {
/* ****************************************************** */ /* ****************************************************** */
void ndpi_free_automa(void *_automa) { void ndpi_free_automa(void *_automa) {
ac_automata_release((AC_AUTOMATA_t *) _automa, 0); ac_automata_release((AC_AUTOMATA_t *) _automa, 1);
} }
/* ****************************************************** */ /* ****************************************************** */