From: Philippe Antoine Date: Mon, 20 Sep 2021 20:00:00 +0000 (+0200) Subject: pcre2: only one DetectParseRegex structure X-Git-Tag: suricata-7.0.0-beta1~1342 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e10d9306608e6cacce5298d9708d4a98dd1dda1b;p=thirdparty%2Fsuricata.git pcre2: only one DetectParseRegex structure --- diff --git a/src/detect-parse.c b/src/detect-parse.c index 1d2b963d91..e4491d8e12 100644 --- a/src/detect-parse.c +++ b/src/detect-parse.c @@ -2440,16 +2440,6 @@ int DetectParsePcreExec( } void DetectParseFreeRegex(DetectParseRegex *r) -{ - if (r->regex) { - pcre2_code_free(r->regex); - } - if (r->match) { - pcre2_match_data_free(r->match); - } -} - -void DetectParseFreePCRE2(DetectParseRegex2 *r) { if (r->regex) { pcre2_code_free(r->regex); @@ -2462,8 +2452,6 @@ void DetectParseFreePCRE2(DetectParseRegex2 *r) } } -static DetectParseRegex2 *g_detect_pcre2_list = NULL; - void DetectParseFreeRegexes(void) { DetectParseRegex *r = g_detect_parse_regex_list; @@ -2476,15 +2464,6 @@ void DetectParseFreeRegexes(void) r = next; } g_detect_parse_regex_list = NULL; - - DetectParseRegex2 *r2 = g_detect_pcre2_list; - while (r2) { - DetectParseRegex2 *next = r2->next; - DetectParseFreePCRE2(r2); - SCFree(r2); - r2 = next; - } - g_detect_pcre2_list = NULL; } /** \brief add regex and/or study to at exit free list @@ -2524,20 +2503,11 @@ bool DetectSetupParseRegexesOpts(const char *parse_str, DetectParseRegex *detect return true; } -/** \brief add pcre2 to at exit free list - */ -static void DetectPCRE2AddToFreeList(DetectParseRegex2 *detect_parse) -{ - // TODO g_detect_parse_regex_list - detect_parse->next = g_detect_pcre2_list; - g_detect_pcre2_list = detect_parse; -} - -DetectParseRegex2 *DetectSetupPCRE2(const char *parse_str, int opts) +DetectParseRegex *DetectSetupPCRE2(const char *parse_str, int opts) { int en; PCRE2_SIZE eo; - DetectParseRegex2 *detect_parse = SCCalloc(1, sizeof(DetectParseRegex2)); + DetectParseRegex *detect_parse = SCCalloc(1, sizeof(DetectParseRegex)); if (detect_parse == NULL) { return NULL; } @@ -2556,7 +2526,8 @@ DetectParseRegex2 *DetectSetupPCRE2(const char *parse_str, int opts) } detect_parse->match = pcre2_match_data_create_from_pattern(detect_parse->regex, NULL); - DetectPCRE2AddToFreeList(detect_parse); + detect_parse->next = g_detect_parse_regex_list; + g_detect_parse_regex_list = detect_parse; return detect_parse; } diff --git a/src/detect-parse.h b/src/detect-parse.h index 9d2218462e..049b130996 100644 --- a/src/detect-parse.h +++ b/src/detect-parse.h @@ -39,18 +39,12 @@ enum { SIG_DIREC_DST }; -typedef struct DetectParseRegex_ { - pcre2_code *regex; - pcre2_match_data *match; - struct DetectParseRegex_ *next; -} DetectParseRegex; - -typedef struct DetectParseRegex2 { +typedef struct DetectParseRegex { pcre2_code *regex; pcre2_match_context *context; pcre2_match_data *match; - struct DetectParseRegex2 *next; -} DetectParseRegex2; + struct DetectParseRegex *next; +} DetectParseRegex; /* prototypes */ Signature *SigAlloc(void); @@ -92,8 +86,7 @@ int WARN_UNUSED DetectSignatureSetAppProto(Signature *s, AppProto alproto); /* parse regex setup and free util funcs */ -void DetectParseFreePCRE2(DetectParseRegex2 *r); -DetectParseRegex2 *DetectSetupPCRE2(const char *parse_str, int opts); +DetectParseRegex *DetectSetupPCRE2(const char *parse_str, int opts); bool DetectSetupParseRegexesOpts(const char *parse_str, DetectParseRegex *parse_regex, int opts); void DetectSetupParseRegexes(const char *parse_str, DetectParseRegex *parse_regex); void DetectParseRegexAddToFreeList(DetectParseRegex *parse_regex); diff --git a/src/detect-pcre.c b/src/detect-pcre.c index c6cf05458e..8746d9b50b 100644 --- a/src/detect-pcre.c +++ b/src/detect-pcre.c @@ -71,8 +71,8 @@ static int pcre_match_limit = 0; static int pcre_match_limit_recursion = 0; -static DetectParseRegex2 *parse_regex; -static DetectParseRegex2 *parse_capture_regex; +static DetectParseRegex *parse_regex; +static DetectParseRegex *parse_capture_regex; #ifdef PCRE2_HAVE_JIT static int pcre2_use_jit = 1; @@ -931,7 +931,7 @@ static void DetectPcreFree(DetectEngineCtx *de_ctx, void *ptr) return; DetectPcreData *pd = (DetectPcreData *)ptr; - DetectParseFreePCRE2(&pd->parse_regex); + DetectParseFreeRegex(&pd->parse_regex); SCFree(pd); return; diff --git a/src/detect-pcre.h b/src/detect-pcre.h index f18631790a..1c28466405 100644 --- a/src/detect-pcre.h +++ b/src/detect-pcre.h @@ -38,7 +38,7 @@ typedef struct DetectPcreData_ { /* pcre options */ - DetectParseRegex2 parse_regex; + DetectParseRegex parse_regex; int opts; uint16_t flags;