aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGuy Harris <guy@alum.mit.edu>2004-02-11 22:52:54 +0000
committerGuy Harris <guy@alum.mit.edu>2004-02-11 22:52:54 +0000
commit60096bfad9fa4b0ba00e5f18ad1015ba84712375 (patch)
tree2f1d2e3662a308999a9de6387364b88b0ea93e03
parentb9b4a23834e80e36c180857bf3cb7065407bd9e0 (diff)
Use -1 rather than 0 as the SCAN_FAILED return value from the lexical
analyzer on errors, and check for SCAN_FAILED from the lexical analyzer and abort the parse if we see it; 0 means "end of input", and we want to distinguish errors from end-of-input, so that we can report errors as such. If we see end-of-input while parsing a double-quoted string, report the error (missing closing quote). Fix the URL for the "Start conditions" section of the Flex manual. svn path=/trunk/; revision=10044
-rw-r--r--epan/dfilter/dfilter-int.h10
-rw-r--r--epan/dfilter/dfilter.c13
-rw-r--r--epan/dfilter/scanner.l17
3 files changed, 31 insertions, 9 deletions
diff --git a/epan/dfilter/dfilter-int.h b/epan/dfilter/dfilter-int.h
index faf4e7cc90..ee2345ceb0 100644
--- a/epan/dfilter/dfilter-int.h
+++ b/epan/dfilter/dfilter-int.h
@@ -1,5 +1,5 @@
/*
- * $Id: dfilter-int.h,v 1.7 2002/08/28 20:40:55 jmayer Exp $
+ * $Id: dfilter-int.h,v 1.8 2004/02/11 22:52:54 guy Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@ethereal.com>
@@ -34,8 +34,8 @@ struct _dfilter_t {
int num_registers;
GList **registers;
gboolean *attempted_load;
- int *interesting_fields;
- int num_interesting_fields;
+ int *interesting_fields;
+ int num_interesting_fields;
};
typedef struct {
@@ -57,9 +57,11 @@ void Dfilter(void*, int, stnode_t*, dfwork_t*);
/* Scanner's lval */
extern stnode_t *df_lval;
+/* Return value for error in scanner. */
+#define SCAN_FAILED -1 /* not 0, as that means end-of-input */
+
/* Set dfilter_error_msg_buf and dfilter_error_msg */
void
dfilter_fail(char *format, ...);
-
#endif
diff --git a/epan/dfilter/dfilter.c b/epan/dfilter/dfilter.c
index 77333226cd..16f6ae9329 100644
--- a/epan/dfilter/dfilter.c
+++ b/epan/dfilter/dfilter.c
@@ -1,5 +1,5 @@
/*
- * $Id: dfilter.c,v 1.14 2002/12/02 23:28:16 guy Exp $
+ * $Id: dfilter.c,v 1.15 2004/02/11 22:52:54 guy Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@ethereal.com>
@@ -204,6 +204,17 @@ dfilter_compile(const gchar *text, dfilter_t **dfp)
df_lval = stnode_new(STTYPE_UNINITIALIZED, NULL);
token = df_lex();
+ /* Check for scanner failure */
+ if (token == SCAN_FAILED) {
+ /* Free the stnode_t that we just generated, since
+ * we're going to give up on parsing. */
+ stnode_free(df_lval);
+ df_lval = NULL;
+
+ /* Give up. */
+ goto FAILURE;
+ }
+
/* Check for end-of-input */
if (token == 0) {
/* Tell the parser that we have reached the end of input */
diff --git a/epan/dfilter/scanner.l b/epan/dfilter/scanner.l
index 78f0f86f40..874a6bca85 100644
--- a/epan/dfilter/scanner.l
+++ b/epan/dfilter/scanner.l
@@ -1,6 +1,6 @@
%{
/*
- * $Id: scanner.l,v 1.14 2004/01/07 05:24:04 gram Exp $
+ * $Id: scanner.l,v 1.15 2004/02/11 22:52:54 guy Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@ethereal.com>
@@ -48,8 +48,6 @@ static int simple(int token);
static gboolean str_to_guint32(char *s, guint32* pint);
GString* quoted_string = NULL;
-#define SCAN_FAILED 0
-
%}
%x RANGE_INT
@@ -128,7 +126,7 @@ GString* quoted_string = NULL;
/* 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/manual/flex-2.5.4/html_node/flex_11.html */
+ http://www.gnu.org/software/flex/manual/html_node/flex_11.html */
BEGIN(DQUOTE);
/* A previous filter that failed to compile due to
@@ -144,6 +142,17 @@ GString* quoted_string = NULL;
quoted_string = g_string_new("");
}
+<DQUOTE><<EOF>> {
+ /* 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 */
+
+ dfilter_fail("The final quote was missing from a quoted string.");
+ return SCAN_FAILED;
+}
+
<DQUOTE>\" {
/* end quote */
char *my_string = g_strdup(quoted_string->str);