diff options
author | Thomas Graf <tgraf@suug.ch> | 2011-03-23 12:39:18 (GMT) |
---|---|---|
committer | Thomas Graf <tgraf@suug.ch> | 2011-03-23 12:39:18 (GMT) |
commit | a0fe7a1c9abe3ab5bf8c9253fab50e114b02b87b (patch) | |
tree | 6449e3505fca5ce28e762ca47a318b62895d24d0 /lib | |
parent | 38db636f7877c7643463e51178e91695485eda27 (diff) | |
download | libnl-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.c | 18 |
1 files changed, 15 insertions, 3 deletions
@@ -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) { |