aboutsummaryrefslogtreecommitdiffstats
path: root/epan
diff options
context:
space:
mode:
authorJoão Valverde <j@v6e.pt>2021-11-27 17:09:51 +0000
committerJoão Valverde <j@v6e.pt>2021-11-27 17:19:11 +0000
commit352390aa97df086e98550c9da53f588bb330ecec (patch)
tree1adb4860510a344ec8461209c51b00a715d2efba /epan
parent01a95db9b73cef619c667910db8de9c3d5f2932e (diff)
dfilter: Need to handle a charconst on the LHS
Diffstat (limited to 'epan')
-rw-r--r--epan/dfilter/semcheck.c64
1 files changed, 64 insertions, 0 deletions
diff --git a/epan/dfilter/semcheck.c b/epan/dfilter/semcheck.c
index f8e7ae2e3f..6ba0bc96ce 100644
--- a/epan/dfilter/semcheck.c
+++ b/epan/dfilter/semcheck.c
@@ -774,6 +774,64 @@ check_relation_LHS_UNPARSED(dfwork_t *dfw, test_op_t st_op,
}
static void
+check_relation_LHS_CHARCONST(dfwork_t *dfw, test_op_t st_op,
+ FtypeCanFunc can_func, gboolean allow_partial_value _U_,
+ stnode_t *st_node _U_,
+ stnode_t *st_arg1, stnode_t *st_arg2)
+{
+ sttype_id_t type2;
+ header_field_info *hfinfo2;
+ df_func_def_t *funcdef;
+ ftenum_t ftype2;
+ fvalue_t *fvalue;
+
+ type2 = stnode_type_id(st_arg2);
+
+ if (type2 == STTYPE_FIELD) {
+ hfinfo2 = stnode_data(st_arg2);
+ ftype2 = hfinfo2->type;
+
+ if (!can_func(ftype2)) {
+ FAIL(dfw, "%s (type=%s) cannot participate in '%s' comparison.",
+ hfinfo2->abbrev, ftype_pretty_name(ftype2),
+ sttype_test_todisplay(st_op));
+ }
+
+ fvalue = dfilter_fvalue_from_charconst(dfw, ftype2, st_arg1);
+ stnode_replace(st_arg1, STTYPE_FVALUE, fvalue);
+ }
+ else if (type2 == STTYPE_STRING || type2 == STTYPE_UNPARSED ||
+ type2 == STTYPE_CHARCONST) {
+ /* Well now that's silly... */
+ FAIL(dfw, "Neither \"%s\" nor \"%s\" are field or protocol names.",
+ stnode_todisplay(st_arg1),
+ stnode_todisplay(st_arg2));
+ }
+ else if (type2 == STTYPE_RANGE) {
+ check_drange_sanity(dfw, st_arg2);
+ fvalue = dfilter_fvalue_from_charconst(dfw, FT_BYTES, st_arg1);
+ stnode_replace(st_arg1, STTYPE_FVALUE, fvalue);
+ }
+ else if (type2 == STTYPE_FUNCTION) {
+ check_function(dfw, st_arg2);
+
+ funcdef = sttype_function_funcdef(st_arg2);
+ ftype2 = funcdef->retval_ftype;
+
+ if (!can_func(ftype2)) {
+ FAIL(dfw, "return value of function %s() (type=%s) cannot participate in '%s' comparison.",
+ funcdef->name, ftype_pretty_name(ftype2), sttype_test_todisplay(st_op));
+ }
+
+ fvalue = dfilter_fvalue_from_charconst(dfw, ftype2, st_arg1);
+ stnode_replace(st_arg1, STTYPE_FVALUE, fvalue);
+ }
+ else {
+ ws_assert_not_reached();
+ }
+}
+
+static void
check_relation_LHS_RANGE(dfwork_t *dfw, test_op_t st_op,
FtypeCanFunc can_func _U_,
gboolean allow_partial_value,
@@ -962,6 +1020,10 @@ check_relation(dfwork_t *dfw, test_op_t st_op,
check_relation_LHS_UNPARSED(dfw, st_op, can_func,
allow_partial_value, st_node, st_arg1, st_arg2);
break;
+ case STTYPE_CHARCONST:
+ check_relation_LHS_CHARCONST(dfw, st_op, can_func,
+ allow_partial_value, st_node, st_arg1, st_arg2);
+ break;
case STTYPE_FUNCTION:
check_relation_LHS_FUNCTION(dfw, st_op, can_func,
allow_partial_value, st_node, st_arg1, st_arg2);
@@ -1020,6 +1082,7 @@ check_relation_contains(dfwork_t *dfw, stnode_t *st_node,
break;
case STTYPE_STRING:
case STTYPE_UNPARSED:
+ case STTYPE_CHARCONST:
FAIL(dfw, "\"%s\" is not a valid operand for contains.", stnode_todisplay(st_arg1));
break;
default:
@@ -1066,6 +1129,7 @@ check_relation_matches(dfwork_t *dfw, stnode_t *st_node,
break;
case STTYPE_STRING:
case STTYPE_UNPARSED:
+ case STTYPE_CHARCONST:
FAIL(dfw, "\"%s\" is not a valid operand for matches.", stnode_todisplay(st_arg1));
break;
default: