aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJoão Valverde <j@v6e.pt>2021-10-14 17:21:10 +0100
committerWireshark GitLab Utility <gerald+gitlab-utility@wireshark.org>2021-10-17 22:53:36 +0000
commit4e5e8066044f830407678c60b6b8b1c5aa21873b (patch)
treea40537c1c578781118fb5ac721da150fb861d4fd
parentac31124514304b7f617201489279f84dc53aa575 (diff)
dfilter: Do not chain matches expressions
It is always an error to chain regexes using the logic for "le" and "eq". var matches "regex1" matches "regex2" => var matches "regex1" and "regex1" matches "regex2" Before: Filter: tcp matches "abc$" matches "^cde" dftest: Neither "abc$" nor "^cde" are field or protocol names. Filter: "abc$" matches tcp matches "^cde" dftest: Neither "abc$" nor "tcp" are field or protocol names. After: Filter: tcp matches "abc$" matches "^cde" dftest: "matches" was unexpected in this context. Filter: "abc$" matches tcp matches "^cde" dftest: "matches" was unexpected in this context.
-rw-r--r--epan/dfilter/grammar.lemon18
1 files changed, 11 insertions, 7 deletions
diff --git a/epan/dfilter/grammar.lemon b/epan/dfilter/grammar.lemon
index b2666710a2..d3dc79ea9c 100644
--- a/epan/dfilter/grammar.lemon
+++ b/epan/dfilter/grammar.lemon
@@ -76,9 +76,11 @@ any "error" symbols are shifted, if possible. */
}
switch(stnode_type_id(TOKEN)) {
- case STTYPE_UNINITIALIZED:
+ case STTYPE_UNINITIALIZED: /* fall-through */
+ case STTYPE_UNPARSED:
if (stnode_token_value(TOKEN) != NULL)
- dfilter_fail(dfw, "Syntax error near \"%s\".", stnode_token_value(TOKEN));
+ dfilter_fail(dfw, "\"%s\" was unexpected in this context.",
+ stnode_token_value(TOKEN));
else
dfilter_fail(dfw, "Syntax error.");
break;
@@ -90,10 +92,6 @@ any "error" symbols are shifted, if possible. */
dfilter_fail(dfw, "The character constant \"%s\" was unexpected in this context.",
(char *)stnode_data(TOKEN));
break;
- case STTYPE_UNPARSED:
- dfilter_fail(dfw, "\"%s\" was unexpected in this context.",
- (char *)stnode_data(TOKEN));
- break;
/* These aren't handed to use as terminal tokens from
the scanner, so was can assert that we'll never
see them here. */
@@ -274,7 +272,6 @@ rel_binop(O) ::= TEST_LT. { O = TEST_OP_LT; }
rel_binop(O) ::= TEST_LE. { O = TEST_OP_LE; }
rel_binop(O) ::= TEST_BITWISE_AND. { O = TEST_OP_BITWISE_AND; }
rel_binop(O) ::= TEST_CONTAINS. { O = TEST_OP_CONTAINS; }
-rel_binop(O) ::= TEST_MATCHES. { O = TEST_OP_MATCHES; }
/* Relational tests */
relation_test(T) ::= entity(E) rel_binop(O) entity(F).
@@ -304,6 +301,13 @@ relation_test(T) ::= entity(E) rel_binop(O) relation_test(R).
sttype_test_set2(T, TEST_OP_AND, L, R);
}
+/* "matches" does not chain with other relational tests. */
+relation_test(T) ::= entity(E) TEST_MATCHES entity(F).
+{
+ T = stnode_new(STTYPE_TEST, NULL, NULL);
+ sttype_test_set2(T, TEST_OP_MATCHES, E, F);
+}
+
relation_test(T) ::= entity(E) TEST_IN LBRACE set_node_list(L) RBRACE.
{
stnode_t *S;