summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorThomas Graf <tgraf@suug.ch>2011-03-23 12:39:18 (GMT)
committerThomas Graf <tgraf@suug.ch>2011-03-23 12:39:18 (GMT)
commita0fe7a1c9abe3ab5bf8c9253fab50e114b02b87b (patch)
tree6449e3505fca5ce28e762ca47a318b62895d24d0 /lib
parent38db636f7877c7643463e51178e91695485eda27 (diff)
downloadlibnl-a0fe7a1c9abe3ab5bf8c9253fab50e114b02b87b.zip
libnl-a0fe7a1c9abe3ab5bf8c9253fab50e114b02b87b.tar.gz
libnl-a0fe7a1c9abe3ab5bf8c9253fab50e114b02b87b.tar.bz2
Omit empty nested attributes
Check for empty nested attributes in nla_nest_end() and omit the attribute alltogether if is is the case.
Diffstat (limited to 'lib')
-rw-r--r--lib/attr.c18
1 files changed, 15 insertions, 3 deletions
diff --git a/lib/attr.c b/lib/attr.c
index cccd50d..a045351 100644
--- a/lib/attr.c
+++ b/lib/attr.c
@@ -1151,10 +1151,22 @@ struct nlattr *nla_nest_start(struct nl_msg *msg, int attrtype)
*/
int nla_nest_end(struct nl_msg *msg, struct nlattr *start)
{
- size_t pad;
+ size_t pad, len;
- start->nla_len = (unsigned char *) nlmsg_tail(msg->nm_nlh) -
- (unsigned char *) start;
+ len = (void *) nlmsg_tail(msg->nm_nlh) - (void *) start;
+
+ if (len == NLA_HDRLEN) {
+ /*
+ * Kernel can't handle empty nested attributes, trim the
+ * attribute header again
+ */
+ msg->nm_nlh->nlmsg_len -= NLA_HDRLEN;
+ memset(nlmsg_tail(msg->nm_nlh), 0, NLA_HDRLEN);
+
+ return 0;
+ }
+
+ start->nla_len = len;
pad = NLMSG_ALIGN(msg->nm_nlh->nlmsg_len) - msg->nm_nlh->nlmsg_len;
if (pad > 0) {