dfilter: Fix crash with a constant arithmetic expression
This commit is contained in:
parent
3ddb017a88
commit
540b71d738
|
@ -581,8 +581,7 @@ gen_entity(dfwork_t *dfw, stnode_t *st_arg, GSList **jumps_ptr)
|
|||
val = gen_arithmetic(dfw, st_arg, jumps_ptr);
|
||||
}
|
||||
else {
|
||||
WS_DEBUG_HERE("sttype is %s", stnode_type_name(st_arg));
|
||||
ws_assert_not_reached();
|
||||
ws_error("Invalid sttype: %s", stnode_type_name(st_arg));
|
||||
}
|
||||
return val;
|
||||
}
|
||||
|
|
|
@ -1369,13 +1369,17 @@ static void
|
|||
semcheck(dfwork_t *dfw, stnode_t *st_node)
|
||||
{
|
||||
LOG_NODE(st_node);
|
||||
ftenum_t ftype;
|
||||
|
||||
switch (stnode_type_id(st_node)) {
|
||||
case STTYPE_TEST:
|
||||
check_test(dfw, st_node);
|
||||
break;
|
||||
case STTYPE_ARITHMETIC:
|
||||
check_arithmetic(dfw, st_node, FT_NONE);
|
||||
ftype = check_arithmetic(dfw, st_node, FT_NONE);
|
||||
if (ftype == FT_NONE) {
|
||||
FAIL(dfw, st_node, "Constant expression is invalid.");
|
||||
}
|
||||
break;
|
||||
case STTYPE_SLICE:
|
||||
check_slice_sanity(dfw, st_node, FT_NONE);
|
||||
|
|
|
@ -264,6 +264,11 @@ class case_arithmetic(unittest.TestCase):
|
|||
dfilter = "1 + 2 == 2 + 1"
|
||||
checkDFilterFail(dfilter, error)
|
||||
|
||||
def test_add_6(self, checkDFilterFail):
|
||||
error = 'Constant expression is invalid'
|
||||
dfilter = "1 - 2"
|
||||
checkDFilterFail(dfilter, error)
|
||||
|
||||
def test_sub_1(self, checkDFilterCount):
|
||||
dfilter = "udp.srcport == udp.dstport - 1"
|
||||
checkDFilterCount(dfilter, 2)
|
||||
|
|
Loading…
Reference in New Issue