json: BASECHAIN flag no longer implies presence of priority expression
Florian Westphal
maintainerPATCH 1/1 json: BASECHAIN flag no longer implies presence of priority expression
This is a followup to44ea19364637 ("src: BASECHAIN flag no longer implies presence of priority expression"):
feeding the same bogon file into nft -j we get a very similar crash.
Signed-off-by Florian Westphal <[email protected]>
--- src/json.c | 32 ++++++++++++------- .../bogons/nft-j-f/null_ingress_type_crash | 6 ++++ 2 files changed, 26 insertions(+), 12 deletions(-) create mode 100644 tests/shell/testcases/bogons/nft-j-f/null_ingress_type_crash
src/json.c +20 -12
@@ -294,8 +294,7 @@ static json_t *rule_print_json(struct output_ctx *octx,static json_t *chain_print_json (const struct chain *chain) { -json_t *root, *tmp, *devs =NULL ; -int priority, policy, i; +json_t *root; root = nft_json_pack("{s:s, s:s, s:s, s:I}", "family", family2str(chain->handle.family),
@@ -307,8 +306,12 @@ static json_t *chain_print_json(const struct chain *chain)json_object_set_new (root,"comment" ,json_string (chain->comment));if (chain->flags &CHAIN_F_BASECHAIN ) { -mpz_export_data (&priority, chain->priority.expr->value, -BYTEORDER_HOST_ENDIAN ,sizeof (int )); +json_t *tmp =NULL , *devs =NULL ; +int priority =0 , policy, i; + +if (chain->priority.expr) +mpz_export_data (&priority, chain->priority.expr->value, +BYTEORDER_HOST_ENDIAN ,sizeof (int ));if (chain->policy) { mpz_export_data(&policy, chain->policy->value,
@@ -317,12 +320,15 @@ static json_t *chain_print_json(const struct chain *chain) policy =NF_ACCEPT ; } - tmp =nft_json_pack ("{s:s, s:s, s:i, s:s}" , -"type" , chain->type.str, -"hook" ,hooknum2str (chain->handle.family, - chain->hook.num), -"prio" , priority, -"policy" ,chain_policy2str (policy)); +if (chain->type.str) + tmp =nft_json_pack ("{s:s, s:s, s:i, s:s}" , +"type" , chain->type.str, +"hook" ,hooknum2str (chain->handle.family, + chain->hook.num), +"prio" , priority, +"policy" ,chain_policy2str (policy)); +else + tmp =NULL ;for (i =0 ; i < chain->dev_array_len; i++) {const char *dev = chain->dev_array[i];
@@ -336,8 +342,10 @@ static json_t *chain_print_json(const struct chain *chain)if (devs)json_object_set_new (root,"dev" , devs); -json_object_update (root, tmp); -json_decref (tmp); +if (tmp) { +json_object_update (root, tmp); +json_decref (tmp); + } }return nft_json_pack ("{s:o}" ,"chain" , root);
tests/shell/testcases/bogons/nft-j-f/null_ingress_type_crash new file +6 -0
@@ -0,0 +1,6 @@ +table netdev filter1 { + chain c { + devices = { lo } + } +} +list ruleset
Signature · 1 line
2.49.0