From 9ef02ef7d0e8252a656650bc1426caafec6d906f Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Wed, 13 Jul 2022 12:02:40 +0200 Subject: [PATCH] platform/netlink: ensure padding is zero in _nest_end() nla_reserve() also ensures that the padding is zero, and only the padding. Thus, when we call nla_reserve(), we need to zero the padding ourselves. --- src/libnm-platform/nm-netlink.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/libnm-platform/nm-netlink.c b/src/libnm-platform/nm-netlink.c index 77fffc0bff..f6b1d8b883 100644 --- a/src/libnm-platform/nm-netlink.c +++ b/src/libnm-platform/nm-netlink.c @@ -584,14 +584,18 @@ _nest_end(struct nl_msg *msg, struct nlattr *start, int keep_empty) pad = NLMSG_ALIGN(msg->nm_nlh->nlmsg_len) - msg->nm_nlh->nlmsg_len; if (pad > 0) { + void *p; + /* * Data inside attribute does not end at a alignment boundary. * Pad accordingly and account for the additional space in * the message. nlmsg_reserve() may never fail in this situation, * the allocate message buffer must be a multiple of NLMSG_ALIGNTO. */ - if (!nlmsg_reserve(msg, pad, 0)) + p = nlmsg_reserve(msg, pad, 0); + if (!p) g_return_val_if_reached(-NME_BUG); + memset(p, 0, pad); } return 0;