From: Phil Sutter Date: Thu, 14 Dec 2017 19:40:23 +0000 (+0100) Subject: ruleset: Avoid reading garbage in nftnl_ruleset_cb() X-Git-Tag: libnftnl-1.0.9~6 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=dbaf6ea8f6a1a1e7f1d5abc2e4e2fef891c471b7;p=thirdparty%2Flibnftnl.git ruleset: Avoid reading garbage in nftnl_ruleset_cb() If nftnl_ruleset_json_parse() is called with arg == NULL, ctx.data is left uninitialized and will later be used in nftnl_ruleset_cb(). Avoid this by using a C99-style initializer for 'ctx' which sets all omitted fields to zero. Signed-off-by: Phil Sutter Signed-off-by: Pablo Neira Ayuso --- diff --git a/src/ruleset.c b/src/ruleset.c index 3de9b872..cf86ca68 100644 --- a/src/ruleset.c +++ b/src/ruleset.c @@ -519,11 +519,11 @@ static int nftnl_ruleset_json_parse(const void *json, json_error_t error; int i, len; const char *key; - struct nftnl_parse_ctx ctx; - - ctx.cb = cb; - ctx.format = type; - ctx.flags = 0; + struct nftnl_parse_ctx ctx = { + .cb = cb, + .format = type, + .flags = 0, + }; ctx.set_list = nftnl_set_list_alloc(); if (ctx.set_list == NULL)