]> git.ipfire.org Git - thirdparty/nftables.git/commitdiff
netlink: Avoid memleak in error path of netlink_delinearize_set()
authorPhil Sutter <phil@nwl.cc>
Fri, 11 Jun 2021 14:43:21 +0000 (16:43 +0200)
committerPhil Sutter <phil@nwl.cc>
Mon, 14 Jun 2021 11:31:07 +0000 (13:31 +0200)
Duplicate string 'comment' later when the function does not fail
anymore.

Fixes: 0864c2d49ee8a ("src: add comment support for set declarations")
Signed-off-by: Phil Sutter <phil@nwl.cc>
src/netlink.c

index e91b06e3ea971ac221e75beaa79ccf8805462d5b..41cce3379ca5021a299bc20d89e1b6b394231709 100644 (file)
@@ -867,7 +867,7 @@ struct set *netlink_delinearize_set(struct netlink_ctx *ctx,
                if (ud[NFTNL_UDATA_SET_DATA_TYPEOF])
                        typeof_expr_data = set_make_key(ud[NFTNL_UDATA_SET_DATA_TYPEOF]);
                if (ud[NFTNL_UDATA_SET_COMMENT])
-                       comment = xstrdup(nftnl_udata_get(ud[NFTNL_UDATA_SET_COMMENT]));
+                       comment = nftnl_udata_get(ud[NFTNL_UDATA_SET_COMMENT]);
        }
 
        key = nftnl_set_get_u32(nls, NFTNL_SET_KEY_TYPE);
@@ -905,7 +905,7 @@ struct set *netlink_delinearize_set(struct netlink_ctx *ctx,
        set->handle.set.name = xstrdup(nftnl_set_get_str(nls, NFTNL_SET_NAME));
        set->automerge     = automerge;
        if (comment)
-               set->comment = comment;
+               set->comment = xstrdup(comment);
 
        init_list_head(&set_parse_ctx.stmt_list);