cache: don't crash when filter is NULL
Florian Westphal
maintainerPATCH 1/1 cache: don't crash when filter is NULL
a delete request will cause a crash in obj_cache_dump, move the deref into the filter block.
Fixes dbff26bfba83 ("cache: consolidate reset command")
Signed-off-by Florian Westphal <[email protected]>
--- src/cache.c | 6 ++++-- .../testcases/bogons/nft-f/delete_nonexistant_object_crash | 1 + 2 files changed, 5 insertions(+), 2 deletions(-) create mode 100644 tests/shell/testcases/bogons/nft-f/delete_nonexistant_object_crash
src/cache.c +4 -2
@@ -902,6 +902,7 @@ static struct nftnl_obj_list *obj_cache_dump(struct netlink_ctx *ctx,int family =NFPROTO_UNSPEC ;const char *table =NULL ;const char *obj =NULL ; +bool reset = false;bool dump = true;if (filter) {
@@ -914,9 +915,10 @@ static struct nftnl_obj_list *obj_cache_dump(struct netlink_ctx *ctx, }if (filter->list.obj_type) type = filter->list.obj_type; + + reset = filter->reset.obj; } - obj_list =mnl_nft_obj_dump (ctx, family, table, obj, type, dump, - filter->reset.obj); + obj_list =mnl_nft_obj_dump (ctx, family, table, obj, type, dump, reset);if (!obj_list) {if (errno ==EINTR )return NULL ;
tests/shell/testcases/bogons/nft-f/delete_nonexistant_object_crash new file +1 -0
@@ -0,0 +1 @@ +delete quota a b
Signature · 1 line
2.49.0
Quoted 5 lines · Florian Westphal
a delete request will cause a crash in
obj_cache_dump, move the deref into the filter block.Fixes dbff26bfba83 ("cache: consolidate reset command")Signed-off-by Florian Westphal <[email protected]>
Reviewed-by Pablo Neira Ayuso <[email protected]>
Thanks.
Quoted 42 lines
--- src/cache.c | 6 ++++-- .../testcases/bogons/nft-f/delete_nonexistant_object_crash | 1 + 2 files changed, 5 insertions(+), 2 deletions(-) create mode 100644 tests/shell/testcases/bogons/nft-f/delete_nonexistant_object_crashsrc/cache.c +4
-2@@ -902,6 +902,7 @@ static struct nftnl_obj_list *obj_cache_dump(struct netlink_ctx *ctx,int family =NFPROTO_UNSPEC ;const char *table =NULL ;const char *obj =NULL ; +bool reset = false;bool dump = true;if (filter) {@@ -914,9 +915,10 @@ static struct nftnl_obj_list *obj_cache_dump(struct netlink_ctx *ctx, }if (filter->list.obj_type) type = filter->list.obj_type; + + reset = filter->reset.obj; } - obj_list =mnl_nft_obj_dump (ctx, family, table, obj, type, dump, - filter->reset.obj); + obj_list =mnl_nft_obj_dump (ctx, family, table, obj, type, dump, reset);if (!obj_list) {if (errno ==EINTR )return NULL ;tests/shell/testcases/bogons/nft-f/delete_nonexistant_object_crash new file +1
-0@@ -0,0 +1 @@ +delete quota a bSignature · 1 line
2.49.0
Pablo Neira Ayuso
maintainerQuoted 8 lines · Pablo Neira Ayuso
Quoted 5 lines · Florian Westphal
a delete request will cause a crash in
obj_cache_dump, move the deref into the filter block.Fixes dbff26bfba83 ("cache: consolidate reset command")Signed-off-by Florian Westphal <[email protected]>Reviewed-by Pablo Neira Ayuso <[email protected]>
BTW. Same pattern in:
- rule_cache_dump()
Maybe collapse this chunk too?
src/cache.c +4 -2
@@ -714,6 +714,7 @@ static int rule_cache_dump(struct netlink_ctx *ctx, const struct handle *h,const char *chain =NULL ;uint64_t rule_handle =0 ;int family = h->family; +bool reset = false;bool dump = true;if (filter) {
@@ -727,11 +728,12 @@ static int rule_cache_dump(struct netlink_ctx *ctx, const struct handle *h, }if (filter->list.family) family = filter->list.family; + + reset = filter->reset.rule; } rule_cache =mnl_nft_rule_dump (ctx, family, - table, chain, rule_handle, dump, - filter->reset.rule); + table, chain, rule_handle, dump, reset);if (rule_cache ==NULL ) {if (errno ==EINTR )return -1 ;