From 82ced8965c86f242eb6ccfbad7c5b1c49fdcf1c2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Valverde?= Date: Sun, 31 Oct 2021 15:52:05 +0000 Subject: [PATCH] dfilter: Free a scanner string earlier --- epan/dfilter/scanner.l | 50 +++++++++--------------------------------- 1 file changed, 10 insertions(+), 40 deletions(-) diff --git a/epan/dfilter/scanner.l b/epan/dfilter/scanner.l index 19df8b4688..b67492a04c 100644 --- a/epan/dfilter/scanner.l +++ b/epan/dfilter/scanner.l @@ -161,23 +161,14 @@ static int set_lval_str(int token, const char *token_value); [rR]{0,1}\042 { /* start quote of a quoted string */ - /* The example of how to scan for strings was taken from - the flex 2.5.4 manual, from the section "Start Conditions". - See: - http://www.gnu.org/software/flex/manual/html_node/flex_11.html */ - + /* + * The example of how to scan for strings was taken from + * the flex manual, from the section "Start Conditions". + * See: https://westes.github.io/flex/manual/Start-Conditions.html + */ BEGIN(DQUOTE); - /* A previous filter that failed to compile due to - a missing end quote will have left quoted_string set - to something. Clear it now that we are starting - a new quoted string. */ - if (yyextra->quoted_string) { - g_string_free(yyextra->quoted_string, TRUE); - /* Don't set quoted_string to NULL, as we - do in other quoted_string-cleanup code, as we're - about to set it in the next line. */ - } yyextra->quoted_string = g_string_new(""); + if (yytext[0] == 'r' || yytext[0] == 'R') { /* * This is a raw string (like in Python). Rules: 1) The two @@ -197,11 +188,8 @@ static int set_lval_str(int token, const char *token_value); <> { /* unterminated string */ - /* The example of how to handle unclosed strings was taken from - the flex 2.5.4 manual, from the section "End-of-file rules". - See: - http://www.gnu.org/software/flex/manual/html_node/flex_13.html */ - + g_string_free(yyextra->quoted_string, TRUE); + yyextra->quoted_string = NULL; dfilter_fail(yyextra->dfw, "The final quote was missing from a quoted string."); return SCAN_FAILED; } @@ -275,32 +263,14 @@ static int set_lval_str(int token, const char *token_value); \047 { /* start quote of a quoted character value */ - /* The example of how to scan for strings was taken from - the Flex manual, from the section "Start Conditions". - See: - http://flex.sourceforge.net/manual/Start-Conditions.html#Start-Conditions */ - BEGIN(SQUOTE); - /* A previous filter that failed to compile due to - a missing end quote will have left quoted_string set - to something. Clear it now that we are starting - a new quoted string. */ - if (yyextra->quoted_string) { - g_string_free(yyextra->quoted_string, TRUE); - /* Don't set quoted_string to NULL, as we - do in other quoted_string-cleanup code, as we're - about to set it in the next line. */ - } yyextra->quoted_string = g_string_new("'"); } <> { /* unterminated character value */ - /* The example of how to handle unclosed strings was taken from - the Flex manual, from the section "End-of-file rules". - See: - http://flex.sourceforge.net/manual/EOF.html#EOF.html */ - + g_string_free(yyextra->quoted_string, TRUE); + yyextra->quoted_string = NULL; dfilter_fail(yyextra->dfw, "The final quote was missing from a character constant."); return SCAN_FAILED; }