Fixes for monitor/echo mode with maps
Phil Sutter
reviewercover Fixes for monitor/echo mode with maps
Patch 1 fixes a segfault when trying to add a rule referring to a map and adds a relevant test case. Patch 2 fixes for wrong format of map values, this is already covered by existing tests. Patch 3 merely improves versatility of tests/monitor/run-tests.sh a bit.
Phil Sutter (3):
monitor: Do not decompose non-anonymous sets
monitor: Fix for use after free when printing map elements
tests: monitor: Support running individual test cases
src/monitor.c | 5 +++-- tests/monitor/run-tests.sh | 9 +++++++-- tests/monitor/testcases/set-interval.t | 20 ++++++++++++++++++++ 3 files changed, 30 insertions(+), 4 deletions(-) create mode 100644 tests/monitor/testcases/set-interval.t
Signature · 1 line
2.24.1
Phil Sutter
reviewerPATCH 1/3 monitor: Do not decompose non-anonymous sets
They have been decomposed already, trying to do that again causes a segfault. This is a similar fix as in commit 8ecb885589591 ("src:
restore --echo with anonymous sets").
--- src/monitor.c | 2 +- tests/monitor/testcases/set-interval.t | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) create mode 100644 tests/monitor/testcases/set-interval.t
src/monitor.c +1 -1
@@ -500,7 +500,7 @@ static int netlink_events_obj_cb(const struct nlmsghdr *nlh, int type,static void rule_map_decompose_cb (struct set *s,void *data) { -if (s->flags &NFT_SET_INTERVAL ) +if (s->flags & (NFT_SET_INTERVAL &NFT_SET_ANONYMOUS ))interval_map_decompose (s->init); }
tests/monitor/testcases/set-interval.t new file +20 -0
@@ -0,0 +1,20 @@ +# setup first +I add table ip t +I add chain ip t c +O - +J {"add": {"table": {"family": "ip", "name": "t", "handle": 0}}} +J {"add": {"chain": {"family": "ip", "table": "t", "name": "c", "handle": 0}}} + +# add set with elements, monitor output expectedly differs +I add set ip t s { type inet_service; flags interval; elements = { 20, 30-40 }; } +O add set ip t s { type inet_service; flags interval; } +O add element ip t s { 20 } +O add element ip t s { 30-40 } +J {"add": {"set": {"family": "ip", "name": "s", "table": "t", "type": "inet_service", "handle": 0, "flags": ["interval"]}}} +J {"add": {"element": {"family": "ip", "table": "t", "name": "s", "elem": {"set": [20]}}}} +J {"add": {"element": {"family": "ip", "table": "t", "name": "s", "elem": {"set": [{"range": [30, 40]}]}}}} + +# this would crash nft +I add rule ip t c tcp dport @s +O - +J {"add": {"rule": {"family": "ip", "table": "t", "chain": "c", "handle": 0, "expr": [{"match": {"op": "==", "left": {"payload": {"protocol": "tcp", "field": "dport"}}, "right": "@s"}}]}}}
Signature · 1 line
2.24.1
Re: [nft PATCH 1/3] monitor: Do not decompose non-anonymous sets
Quoted 5 lines · Phil Sutter
They have been decomposed already, trying to do that again causes a segfault. This is a similar fix as in commit
8ecb885589591("src:
restore --echo with anonymous sets").Signed-off-by Phil Sutter <[email protected]>
Phil Sutter
reviewerPATCH 2/3 monitor: Fix for use after free when printing map elements
In reply to Phil SutterWhen populating the dummy set, 'data' field must be cloned just like 'key' field.
--- src/monitor.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
src/monitor.c +2 -1
@@ -401,7 +401,8 @@ static int netlink_events_setelem_cb(const struct nlmsghdr *nlh, int type,*/ dummyset =set_alloc (monh->loc); dummyset->key =expr_clone (set->key); - dummyset->data = set->data; +if (set->data) + dummyset->data =expr_clone (set->data); dummyset->flags = set->flags; dummyset->init =set_expr_alloc (monh->loc, set);
Signature · 1 line
2.24.1
Re: [nft PATCH 2/3] monitor: Fix for use after free when printing map elements
Quoted 5 lines · Phil Sutter
When populating the dummy set, 'data' field must be cloned just like 'key' field.
Fixes 343a51702656a ("src: store expr, not dtype to track data in sets")Signed-off-by Phil Sutter <[email protected]>
Phil Sutter
reviewerPATCH 3/3 tests: monitor: Support running individual test cases
In reply to Phil SutterRecognize testcase paths on command line and limit testing on those only.
--- tests/monitor/run-tests.sh | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-)
tests/monitor/run-tests.sh +7 -2
@@ -108,6 +108,7 @@ echo_run_test() { touch $output_file } +testcases="" while [ -n "$1" ]; do case "$1" in -d|--debug)
@@ -118,11 +119,15 @@ while [ -n "$1" ]; do test_json=true shift ;; + testcases/*.t) + testcases+=" $1" + shift + ;; *) echo "unknown option '$1'" ;& -h|--help) - echo "Usage: $(basename $0) [-j|--json] [-d|--debug]" + echo "Usage: $(basename $0) [-j|--json] [-d|--debug] [testcase ...]" exit 1 ;; esac
@@ -138,7 +143,7 @@ for variant in $variants; do run_test=${variant}_run_test output_append=${variant}_output_append - for testcase in testcases/*.t; do + for testcase in ${testcases:-testcases/*.t}; do echo "$variant: running tests from file $(basename $testcase)" # files are like this: #
Signature · 1 line
2.24.1
Re: [nft PATCH 3/3] tests: monitor: Support running individual test cases
Quoted 4 lines · Phil Sutter
Recognize testcase paths on command line and limit testing on those only.
Signed-off-by Phil Sutter <[email protected]>