dect
/
libnl
Archived
13
0
Fork 0

Omit empty nested attributes

Check for empty nested attributes in nla_nest_end() and omit the
attribute alltogether if is is the case.
This commit is contained in:
Thomas Graf 2011-03-23 13:39:18 +01:00
parent 38db636f78
commit a0fe7a1c9a
1 changed files with 15 additions and 3 deletions

View File

@ -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) {