path: root/src
diff options
authorCarlos Falgueras García <>2016-05-17 18:00:16 +0200
committerPablo Neira Ayuso <>2016-05-25 10:34:47 +0200
commit8979727084d90e6061c8d0f562f8f12e784a657d (patch)
tree94786a184e6119e2f94692b0c43e5f504abaaac8 /src
parent4ca26afeef12c59128ffde8505207847037ce365 (diff)
netlink_linearize: do not duplicate user data when linearizing user data
Otherwise, we memory leak this area since nftnl_rule_set_data() now makes a copy of the user data which receives. This is happening since libnftnl's ("rule: Fix segfault due to invalid free of rule user data"), it is not necessary make a copy before call it. Note: Carlos originally posted this patch under the name of ("nftables: Fix memory leak linearizing user data"). Signed-off-by: Carlos Falgueras García <> Signed-off-by: Pablo Neira Ayuso <>
Diffstat (limited to 'src')
1 files changed, 3 insertions, 8 deletions
diff --git a/src/netlink_linearize.c b/src/netlink_linearize.c
index 62bb25c4..98c22d88 100644
--- a/src/netlink_linearize.c
+++ b/src/netlink_linearize.c
@@ -1127,8 +1127,6 @@ void netlink_linearize_rule(struct netlink_ctx *ctx, struct nftnl_rule *nlr,
if (rule->comment) {
struct nftnl_udata_buf *udata;
- uint32_t udlen;
- void *ud;
udata = nftnl_udata_buf_alloc(NFT_USERDATA_MAXLEN);
if (!udata)
@@ -1137,12 +1135,9 @@ void netlink_linearize_rule(struct netlink_ctx *ctx, struct nftnl_rule *nlr,
if (!nftnl_udata_put_strz(udata, UDATA_TYPE_COMMENT,
- udlen = nftnl_udata_buf_len(udata);
- ud = xmalloc(udlen);
- memcpy(ud, nftnl_udata_buf_data(udata), udlen);
- nftnl_rule_set_data(nlr, NFTNL_RULE_USERDATA, ud, udlen);
+ nftnl_rule_set_data(nlr, NFTNL_RULE_USERDATA,
+ nftnl_udata_buf_data(udata),
+ nftnl_udata_buf_len(udata));