aboutsummaryrefslogtreecommitdiffstats
path: root/ui
diff options
context:
space:
mode:
authorGuy Harris <guy@alum.mit.edu>2016-03-30 18:44:01 -0700
committerGuy Harris <guy@alum.mit.edu>2016-04-03 22:21:29 +0000
commit59816ef00c6dd09532d80b393ba03f8194aba236 (patch)
treef5e84c67ebe0e69542db94d56db70fa476c0db6c /ui
parente42a43bc58a36848316adae19981878a5f430c46 (diff)
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 'ui')
-rw-r--r--ui/Makefile.am2
-rw-r--r--ui/gtk/file_import_dlg.c7
-rw-r--r--ui/qt/import_text_dialog.cpp8
-rw-r--r--ui/text_import.c20
-rw-r--r--ui/text_import.h2
-rw-r--r--ui/text_import_scanner.l42
6 files changed, 71 insertions, 10 deletions
diff --git a/ui/Makefile.am b/ui/Makefile.am
index 61446b5cd7..a1185688bf 100644
--- a/ui/Makefile.am
+++ b/ui/Makefile.am
@@ -28,6 +28,8 @@ AM_CPPFLAGS = $(INCLUDEDIRS) $(WS_CPPFLAGS) -DDOC_DIR=\"$(docdir)\" \
noinst_LIBRARIES = libui.a libui_dirty.a
+BUILT_SOURCES = $(GENERATED_HEADER_FILES)
+
CLEANFILES = \
doxygen-ui.tag \
libui.a \
diff --git a/ui/gtk/file_import_dlg.c b/ui/gtk/file_import_dlg.c
index 83a16fb893..e901b7bd07 100644
--- a/ui/gtk/file_import_dlg.c
+++ b/ui/gtk/file_import_dlg.c
@@ -517,7 +517,12 @@ file_import_open(text_import_info_t *info)
goto end;
}
- text_import(info);
+ err = text_import(info);
+ if (err != 0) {
+ failure_alert_box("Can't initialize scanner: %s", g_strerror(err));
+ fclose(info->import_text_file);
+ goto end;
+ }
if (fclose(info->import_text_file)) {
read_failure_alert_box(info->import_text_filename, errno);
diff --git a/ui/qt/import_text_dialog.cpp b/ui/qt/import_text_dialog.cpp
index 02479472ca..11b0218fb8 100644
--- a/ui/qt/import_text_dialog.cpp
+++ b/ui/qt/import_text_dialog.cpp
@@ -140,7 +140,13 @@ void ImportTextDialog::convertTextFile() {
return;
}
- text_import(&import_info_);
+ err = text_import(&import_info_);
+ if (err != 0) {
+ failure_alert_box("Can't initialize scanner: %s", g_strerror(err));
+ fclose(import_info_.import_text_file);
+ setResult(QDialog::Rejected);
+ return;
+ }
if (fclose(import_info_.import_text_file))
{
diff --git a/ui/text_import.c b/ui/text_import.c
index 9928ddbc1f..45fddbdde2 100644
--- a/ui/text_import.c
+++ b/ui/text_import.c
@@ -126,6 +126,7 @@
#include "text_import.h"
#include "text_import_scanner.h"
+#include "text_import_scanner_lex.h"
/*--- Options --------------------------------------------------------------------*/
@@ -902,9 +903,12 @@ parse_token (token_t token, char *str)
/*----------------------------------------------------------------------
* Import a text file.
*/
-void
+int
text_import(text_import_info_t *info)
{
+ yyscan_t scanner;
+ int ret;
+
packet_buf = (guint8 *)g_malloc(sizeof(HDR_ETHERNET) + sizeof(HDR_IP) +
sizeof(HDR_SCTP) + sizeof(HDR_DATA_CHUNK) +
IMPORT_MAX_PACKET);
@@ -1014,11 +1018,21 @@ text_import(text_import_info_t *info)
max_offset = info->max_frame_length;
- text_importin = info->import_text_file;
+ if (text_import_lex_init(&scanner) != 0) {
+ ret = errno;
+ g_free(packet_buf);
+ return ret;
+ }
+
+ text_import_set_in(info->import_text_file, scanner);
- text_importlex();
+ text_import_lex(scanner);
+
+ text_import_lex_destroy(scanner);
g_free(packet_buf);
+
+ return 0;
}
/*
diff --git a/ui/text_import.h b/ui/text_import.h
index e430205fda..f6612d61dc 100644
--- a/ui/text_import.h
+++ b/ui/text_import.h
@@ -86,7 +86,7 @@ typedef struct
guint max_frame_length;
} text_import_info_t;
-void text_import(text_import_info_t *info);
+int text_import(text_import_info_t *info);
#ifdef __cplusplus
}
diff --git a/ui/text_import_scanner.l b/ui/text_import_scanner.l
index 9af93643e4..740a38ea22 100644
--- a/ui/text_import_scanner.l
+++ b/ui/text_import_scanner.l
@@ -1,9 +1,19 @@
/* -*-mode: flex-*- */
/*
+ * We want a reentrant scanner.
+ */
+%option reentrant
+
+/*
+ * We don't use input, so don't generate code for it.
+ */
+%option noinput
+
+/*
* We don't use unput, so don't generate code for it.
*/
-%option nounput noinput
+%option nounput
/*
* We don't read interactively from the terminal.
@@ -16,10 +26,23 @@
%option noyywrap
/*
- * Prefix scanner routines with "text_import" rather than "yy", so this scanner
+ * Prefix scanner routines with "text_import_" rather than "yy", so this scanner
* can coexist with other scanners.
*/
-%option prefix="text_import"
+%option prefix="text_import_"
+
+/*
+ * We have to override the memory allocators so that we don't get
+ * "unused argument" warnings from the yyscanner argument (which
+ * we don't use, as we have a global memory allocator).
+ *
+ * We provide, as macros, our own versions of the routines generated by Flex,
+ * which just call malloc()/realloc()/free() (as the Flex versions do),
+ * discarding the extra argument.
+ */
+%option noyyalloc
+%option noyyrealloc
+%option noyyfree
%{
@@ -57,7 +80,6 @@
#include <stdlib.h>
#include "text_import_scanner.h"
-#include "text_import_scanner_lex.h"
/*
* Flex (v 2.5.35) uses this symbol to "exclude" unistd.h
@@ -70,6 +92,18 @@
# pragma warning (disable:4018)
#endif
+/*
+ * Sleazy hack to suppress compiler warnings in yy_fatal_error().
+ */
+#define YY_EXIT_FAILURE ((void)yyscanner, 2)
+
+/*
+ * Macros for the allocators, to discard the extra argument.
+ */
+#define text_import_alloc(size, yyscanner) (void *)malloc(size)
+#define text_import_realloc(ptr, size, yyscanner) (void *)realloc((char *)(ptr), (size))
+#define text_import_free(ptr, yyscanner) free((char *)ptr)
+
%}
hexdigit [0-9A-Fa-f]