From: Patrick McHardy Date: Fri, 28 Nov 2008 11:05:19 +0000 (-0800) Subject: netlink: allow empty nested attributes X-Git-Url: https://git.karo-electronics.de/?a=commitdiff_plain;h=ea5693cc;p=linux-beck.git netlink: allow empty nested attributes validate_nla() currently doesn't allow empty nested attributes. This makes userspace code unnecessarily complicated when starting and ending the nested attribute is done by generic upper level code and the inner attributes are dumped by a module. Add a special case to accept empty nested attributes. When the nested attribute is non empty, the same checks as before are performed. Signed-off-by: Patrick McHardy Signed-off-by: David S. Miller --- diff --git a/net/netlink/attr.c b/net/netlink/attr.c index c83fea7da9a8..56c3ce7fe29a 100644 --- a/net/netlink/attr.c +++ b/net/netlink/attr.c @@ -83,6 +83,12 @@ static int validate_nla(struct nlattr *nla, int maxtype, if (attrlen < NLA_ALIGN(pt->len) + NLA_HDRLEN + nla_len(nla)) return -ERANGE; break; + case NLA_NESTED: + /* a nested attributes is allowed to be empty; if its not, + * it must have a size of at least NLA_HDRLEN. + */ + if (attrlen == 0) + break; default: if (pt->len) minlen = pt->len;