aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJoão Valverde <j@v6e.pt>2022-03-23 10:57:14 +0000
committerJoão Valverde <j@v6e.pt>2022-03-23 11:04:41 +0000
commit2fc8c0e36bb31fc9ded8d0eba230192a9c466041 (patch)
tree09da5b7d6aead299b5cb9cc9ef94af56fe1a111a
parent0335ebdc3ac28a09733b8e1f9e90944be2fba2ab (diff)
dfilter: Handle a bitwise expr on the RHS
-rw-r--r--epan/dfilter/semcheck.c39
-rw-r--r--test/suite_dfilter/group_syntax.py12
2 files changed, 47 insertions, 4 deletions
diff --git a/epan/dfilter/semcheck.c b/epan/dfilter/semcheck.c
index 21075cf24f..7986e6df34 100644
--- a/epan/dfilter/semcheck.c
+++ b/epan/dfilter/semcheck.c
@@ -721,6 +721,19 @@ again:
else if (type2 == STTYPE_PCRE) {
ws_assert(st_op == TEST_OP_MATCHES);
}
+ else if (type2 == STTYPE_BITWISE) {
+ ftype2 = check_bitwise_operation(dfw, st_arg2);
+
+ if (!compatible_ftypes(ftype1, ftype2)) {
+ FAIL(dfw, "%s and %s are not of compatible types.",
+ stnode_todisplay(st_arg1), stnode_todisplay(st_arg2));
+ }
+
+ if (!can_func(ftype2)) {
+ FAIL(dfw, "%s (type=%s) cannot participate in specified comparison.",
+ stnode_todisplay(st_arg2), ftype_pretty_name(ftype2));
+ }
+ }
else {
ws_assert_not_reached();
}
@@ -801,6 +814,19 @@ again:
else if (type2 == STTYPE_PCRE) {
ws_assert(st_op == TEST_OP_MATCHES);
}
+ else if (type2 == STTYPE_BITWISE) {
+ ftype2 = check_bitwise_operation(dfw, st_arg2);
+
+ if (!compatible_ftypes(FT_BYTES, ftype2)) {
+ FAIL(dfw, "%s and %s are not of compatible types.",
+ stnode_todisplay(st_arg1), stnode_todisplay(st_arg2));
+ }
+
+ if (!can_func(ftype2)) {
+ FAIL(dfw, "%s (type=%s) cannot participate in specified comparison.",
+ stnode_todisplay(st_arg2), ftype_pretty_name(ftype2));
+ }
+ }
else {
ws_assert_not_reached();
}
@@ -904,6 +930,19 @@ again:
else if (type2 == STTYPE_PCRE) {
ws_assert(st_op == TEST_OP_MATCHES);
}
+ else if (type2 == STTYPE_BITWISE) {
+ ftype2 = check_bitwise_operation(dfw, st_arg2);
+
+ if (!compatible_ftypes(ftype1, ftype2)) {
+ FAIL(dfw, "%s and %s are not of compatible types.",
+ stnode_todisplay(st_arg1), stnode_todisplay(st_arg2));
+ }
+
+ if (!can_func(ftype2)) {
+ FAIL(dfw, "%s (type=%s) cannot participate in specified comparison.",
+ stnode_todisplay(st_arg2), ftype_pretty_name(ftype2));
+ }
+ }
else {
ws_assert_not_reached();
}
diff --git a/test/suite_dfilter/group_syntax.py b/test/suite_dfilter/group_syntax.py
index b6ceae779c..06fdea2126 100644
--- a/test/suite_dfilter/group_syntax.py
+++ b/test/suite_dfilter/group_syntax.py
@@ -149,10 +149,14 @@ class case_bitwise(unittest.TestCase):
dfilter = "tcp.flags & 0x8"
checkDFilterCount(dfilter, 1)
- def test_exists_1(self, checkDFilterCount):
+ def test_exists_2(self, checkDFilterCount):
+ dfilter = "eth[0] & 1"
+ checkDFilterCount(dfilter, 0)
+
+ def test_equal_1(self, checkDFilterCount):
dfilter = "tcp.flags & 0x0F == 8"
checkDFilterCount(dfilter, 1)
- def test_exists_1(self, checkDFilterCount):
- dfilter = "eth[0] & 1"
- checkDFilterCount(dfilter, 0)
+ def test_equal_2(self, checkDFilterCount):
+ dfilter = "tcp.srcport != tcp.dstport & 0x0F"
+ checkDFilterCount(dfilter, 1)