diff options
author | Guy Harris <guy@alum.mit.edu> | 2016-03-30 18:44:01 -0700 |
---|---|---|
committer | Guy Harris <guy@alum.mit.edu> | 2016-04-03 22:21:29 +0000 |
commit | 59816ef00c6dd09532d80b393ba03f8194aba236 (patch) | |
tree | f5e84c67ebe0e69542db94d56db70fa476c0db6c /epan/dfilter/dfilter.c | |
parent | e42a43bc58a36848316adae19981878a5f430c46 (diff) | |
download | wireshark-59816ef00c6dd09532d80b393ba03f8194aba236.tar.gz |
Make the Flex scanners and YACC parser in libraries reentrant.
master-branch libpcap now generates a reentrant Flex scanner and
Bison/Berkeley YACC parser for capture filter expressions, so it
requires versions of Flex and Bison/Berkeley YACC that support that.
We might as well do the same. For libwiretap, it means we could
actually have multiple K12 text or Ascend/Lucent text files open at the
same time. For libwireshark, it might not be as useful, as we only read
configuration files at startup (which should only happen once, in one
thread) or on demand (in which case, if we ever support multiple threads
running libwireshark, we'd need a mutex to ensure that only one file
reads it), but it's still the right thing to do.
We also require a version of Flex that can write out a header file, so
we change the runlex script to generate the header file ourselves. This
means we require a version of Flex new enough to support --header-file.
Clean up some other stuff encountered in the process.
Change-Id: Id23078c6acea549a52fc687779bb55d715b55c16
Reviewed-on: https://code.wireshark.org/review/14719
Reviewed-by: Guy Harris <guy@alum.mit.edu>
Diffstat (limited to 'epan/dfilter/dfilter.c')
-rw-r--r-- | epan/dfilter/dfilter.c | 37 |
1 files changed, 23 insertions, 14 deletions
diff --git a/epan/dfilter/dfilter.c b/epan/dfilter/dfilter.c index df24b1ced7..151bb5ec7d 100644 --- a/epan/dfilter/dfilter.c +++ b/epan/dfilter/dfilter.c @@ -31,14 +31,10 @@ #include <epan/epan_dissect.h> #include "dfilter.h" #include "dfilter-macro.h" +#include "scanner_lex.h" #define DFILTER_TOKEN_ID_OFFSET 1 -/* From scanner.c */ -void df_scanner_text(const char *text); -void df_scanner_cleanup(void); -int df_lex(void); - /* Holds the singular instance of our Lemon parser object */ static void* ParserObj = NULL; @@ -214,6 +210,9 @@ dfilter_compile(const gchar *text, dfilter_t **dfp, gchar **err_msg) int token; dfilter_t *dfilter; dfwork_t *dfw; + df_scanner_state_t state; + yyscan_t scanner; + YY_BUFFER_STATE in_buffer; gboolean failure = FALSE; const char *depr_test; guint i; @@ -233,21 +232,28 @@ dfilter_compile(const gchar *text, dfilter_t **dfp, gchar **err_msg) return FALSE; } + if (df_lex_init(&scanner) != 0) { + *dfp = NULL; + if (err_msg != NULL) + *err_msg = g_strdup_printf("Can't initialize scanner: %s", + g_strerror(errno)); + return FALSE; + } + + in_buffer = df__scan_string(expanded_text, scanner); + dfw = dfwork_new(); - /* - * XXX - if we're using a version of Flex that supports reentrant lexical - * analyzers, we should put this into the lexical analyzer's state. - */ - global_dfw = dfw; + state.dfw = dfw; + state.quoted_string = NULL; - df_scanner_text(expanded_text); + df_set_extra(&state, scanner); deprecated = g_ptr_array_new(); while (1) { df_lval = stnode_new(STTYPE_UNINITIALIZED, NULL); - token = df_lex(); + token = df_lex(scanner); /* Check for scanner failure */ if (token == SCAN_FAILED) { @@ -307,8 +313,11 @@ dfilter_compile(const gchar *text, dfilter_t **dfp, gchar **err_msg) if (dfw->syntax_error) failure = TRUE; - /* Reset flex */ - df_scanner_cleanup(); + /* Free scanner state */ + if (state.quoted_string != NULL) + g_string_free(state.quoted_string, TRUE); + df__delete_buffer(in_buffer, scanner); + df_lex_destroy(scanner); if (failure) goto FAILURE; |