forked from osmocom/wireshark
dfilter: Need to check validity of LHS of "matches" expression
Fixes #17690, a crash on a failed assertion.
This commit is contained in:
parent
9c2f3b0dc6
commit
c6b68b3ee2
|
@ -1166,6 +1166,25 @@ check_relation(dfwork_t *dfw, const char *relation_string,
|
|||
}
|
||||
}
|
||||
|
||||
static void
|
||||
check_relation_matches(dfwork_t *dfw, stnode_t *st_node,
|
||||
stnode_t *st_arg1, stnode_t *st_arg2)
|
||||
{
|
||||
if (stnode_type_id(st_arg1) == STTYPE_FIELD) {
|
||||
check_relation_LHS_FIELD(dfw, "matches", ftype_can_matches, TRUE, st_node, st_arg1, st_arg2);
|
||||
}
|
||||
else if (stnode_type_id(st_arg1) == STTYPE_FUNCTION) {
|
||||
check_relation_LHS_FUNCTION(dfw, "matches", ftype_can_matches, TRUE, st_node, st_arg1, st_arg2);
|
||||
}
|
||||
else if (stnode_type_id(st_arg1) == STTYPE_RANGE) {
|
||||
check_relation_LHS_RANGE(dfw, "matches", ftype_can_matches, TRUE, st_node, st_arg1, st_arg2);
|
||||
}
|
||||
else {
|
||||
dfilter_fail(dfw, "%s is not a valid operand for matches.", stnode_todisplay(st_arg1));
|
||||
THROW(TypeError);
|
||||
}
|
||||
}
|
||||
|
||||
/* Check the semantics of any type of TEST */
|
||||
static void
|
||||
check_test(dfwork_t *dfw, stnode_t *st_node)
|
||||
|
@ -1242,7 +1261,7 @@ check_test(dfwork_t *dfw, stnode_t *st_node)
|
|||
check_relation(dfw, "contains", TRUE, ftype_can_contains, st_node, st_arg1, st_arg2);
|
||||
break;
|
||||
case TEST_OP_MATCHES:
|
||||
check_relation(dfw, "matches", TRUE, ftype_can_matches, st_node, st_arg1, st_arg2);
|
||||
check_relation_matches(dfw, st_node, st_arg1, st_arg2);
|
||||
break;
|
||||
case TEST_OP_IN:
|
||||
/* Use the ftype_can_eq as the items in the set are evaluated using the
|
||||
|
|
|
@ -28,8 +28,10 @@ string_free(gpointer value)
|
|||
}
|
||||
|
||||
static char *
|
||||
string_tostr(const void *data, gboolean pretty _U_)
|
||||
string_tostr(const void *data, gboolean pretty)
|
||||
{
|
||||
if (pretty)
|
||||
return g_strdup_printf("\"%s\"", (const char *)data);
|
||||
return g_strdup(data);
|
||||
}
|
||||
|
||||
|
|
|
@ -37,11 +37,11 @@ class case_range(unittest.TestCase):
|
|||
|
||||
def test_slice_string_1(self, checkDFilterFail):
|
||||
dfilter = "frame == \"00\"[1]"
|
||||
checkDFilterFail(dfilter, "Range is not supported for entity 00 of type STRING")
|
||||
checkDFilterFail(dfilter, "Range is not supported for entity \"00\" of type STRING")
|
||||
|
||||
def test_slice_unparsed_1(self, checkDFilterFail):
|
||||
dfilter = "a == b[1]"
|
||||
checkDFilterFail(dfilter, "Range is not supported for entity b of type UNPARSED")
|
||||
checkDFilterFail(dfilter, "Range is not supported for entity \"b\" of type UNPARSED")
|
||||
|
||||
def test_slice_func_1(self, checkDFilterSucceed):
|
||||
dfilter = "string(ipx.src.node)[3:2] == \"cc:dd\""
|
||||
|
|
|
@ -47,6 +47,10 @@ class case_syntax(unittest.TestCase):
|
|||
dfilter = r'http.host matches r"update\.microsoft\.c.."'
|
||||
checkDFilterCount(dfilter, 1)
|
||||
|
||||
def test_matches_5(self, checkDFilterFail):
|
||||
dfilter = '"a" matches "b"'
|
||||
checkDFilterFail(dfilter, "not a valid operand for matches")
|
||||
|
||||
def test_equal_1(self, checkDFilterCount):
|
||||
dfilter = 'ip.addr == 10.0.0.5'
|
||||
checkDFilterCount(dfilter, 1)
|
||||
|
|
Loading…
Reference in New Issue