aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPeter Wu <peter@lekensteyn.nl>2018-04-17 17:49:17 +0200
committerAnders Broman <a.broman58@gmail.com>2018-04-18 03:47:58 +0000
commit6a45dcd7a2ab695aade66499cdb61406a2196429 (patch)
treea2723ac78d4e28c457a3d167d9fd63a89b0e47e7
parent699ee5dc529cc2be8a3d1721e506471321fdbc74 (diff)
dfilter: require spaces as set element separator
Previously a filter such as `http.request.method in {"GET"HEAD""}` would be parsed as three strings (GET, HEAD and an empty string). As it seems more likely that people make typos rather than intending to construct such a filter, forbid this by always requiring a whitespace separator. Change-Id: I77e531fd6be072f62dd06aac27f856106c8920c6 Reported-by: Stig Bjørlykke Reviewed-on: https://code.wireshark.org/review/26989 Petri-Dish: Peter Wu <peter@lekensteyn.nl> Tested-by: Petri Dish Buildbot Reviewed-by: Anders Broman <a.broman58@gmail.com>
-rw-r--r--epan/dfilter/dfilter-int.h1
-rw-r--r--epan/dfilter/dfilter.c1
-rw-r--r--epan/dfilter/grammar.lemon4
-rw-r--r--epan/dfilter/scanner.l23
4 files changed, 23 insertions, 6 deletions
diff --git a/epan/dfilter/dfilter-int.h b/epan/dfilter/dfilter-int.h
index 1f8dc00..785f5a3 100644
--- a/epan/dfilter/dfilter-int.h
+++ b/epan/dfilter/dfilter-int.h
@@ -49,6 +49,7 @@ typedef struct {
typedef struct {
dfwork_t *dfw;
GString* quoted_string;
+ gboolean in_set; /* true if parsing set elements for the membership operator */
} df_scanner_state_t;
/* Constructor/Destructor prototypes for Lemon Parser */
diff --git a/epan/dfilter/dfilter.c b/epan/dfilter/dfilter.c
index a3ca2b6..a975f84 100644
--- a/epan/dfilter/dfilter.c
+++ b/epan/dfilter/dfilter.c
@@ -239,6 +239,7 @@ dfilter_compile(const gchar *text, dfilter_t **dfp, gchar **err_msg)
state.dfw = dfw;
state.quoted_string = NULL;
+ state.in_set = FALSE;
df_set_extra(&state, scanner);
diff --git a/epan/dfilter/grammar.lemon b/epan/dfilter/grammar.lemon
index 647816e..72ab511 100644
--- a/epan/dfilter/grammar.lemon
+++ b/epan/dfilter/grammar.lemon
@@ -313,7 +313,7 @@ setnode_list(L) ::= entity(E).
L = g_slist_append(L, NULL);
}
-setnode_list(L) ::= setnode_list(P) entity(E).
+setnode_list(L) ::= setnode_list(P) WHITESPACE entity(E).
{
L = g_slist_append(P, E);
L = g_slist_append(L, NULL);
@@ -326,7 +326,7 @@ setnode_list(L) ::= entity(X) DOTDOT entity(Y).
L = g_slist_append(L, Y);
}
-setnode_list(L) ::= setnode_list(P) entity(X) DOTDOT entity(Y).
+setnode_list(L) ::= setnode_list(P) WHITESPACE entity(X) DOTDOT entity(Y).
{
L = g_slist_append(P, X);
L = g_slist_append(L, Y);
diff --git a/epan/dfilter/scanner.l b/epan/dfilter/scanner.l
index b53be6f..735e37c 100644
--- a/epan/dfilter/scanner.l
+++ b/epan/dfilter/scanner.l
@@ -111,16 +111,30 @@ static void mark_lval_deprecated(const char *s);
%%
-[[:blank:]\n]+ /* ignore whitespace */
+[[:blank:]\n]+ {
+ /* Ignore whitespace, unless set elements are being parsed. Perhaps it
+ * should have used commas from the beginning, but now we are stuck with
+ * whitespace as separators. */
+ if (yyextra->in_set) {
+ return simple(TOKEN_WHITESPACE);
+ }
+}
"(" return simple(TOKEN_LPAREN);
")" return simple(TOKEN_RPAREN);
"," return simple(TOKEN_COMMA);
-"{" return simple(TOKEN_LBRACE);
-".." return simple(TOKEN_DOTDOT);
-"}" return simple(TOKEN_RBRACE);
+
+"{"[[:blank:]\n]* {
+ yyextra->in_set = TRUE;
+ return simple(TOKEN_LBRACE);
+}
+[[:blank:]\n]*".."[[:blank:]\n]* return simple(TOKEN_DOTDOT);
+[[:blank:]\n]*"}" {
+ yyextra->in_set = FALSE;
+ return simple(TOKEN_RBRACE);
+}
"==" return simple(TOKEN_TEST_EQ);
"eq" return simple(TOKEN_TEST_EQ);
@@ -397,6 +411,7 @@ simple(int token)
case TOKEN_COMMA:
case TOKEN_DOTDOT:
case TOKEN_HYPHEN:
+ case TOKEN_WHITESPACE:
case TOKEN_TEST_EQ:
case TOKEN_TEST_NE:
case TOKEN_TEST_GT: