]> granicus.if.org Git - libnl/commitdiff
msg: Avoid returning a negative value for nlmsg_attrlen()
authorThomas Graf <tgraf@suug.ch>
Thu, 27 Jun 2013 16:29:17 +0000 (18:29 +0200)
committerThomas Graf <tgraf@suug.ch>
Thu, 27 Jun 2013 16:29:17 +0000 (18:29 +0200)
If a hdrlen was provided that was greather than the actual
message length, a negative attributes length would result.

This was typically happening for RTM_GETLINK requests where
we can get a away with a 4 bytes header on the request side
but the response would use a 16 bytes header.

This resulted in strange -8 bytes leftover debug messages.

Signed-off-by: Thomas Graf <tgraf@suug.ch>
lib/msg.c

index 6478507c5dbe233a2cb3e11ac3ed0da623574bb7..3c58cb7cdde0c49f97655aa23878697e976f84b2 100644 (file)
--- a/lib/msg.c
+++ b/lib/msg.c
@@ -153,7 +153,7 @@ struct nlattr *nlmsg_attrdata(const struct nlmsghdr *nlh, int hdrlen)
  */
 int nlmsg_attrlen(const struct nlmsghdr *nlh, int hdrlen)
 {
-       return nlmsg_len(nlh) - NLMSG_ALIGN(hdrlen);
+       return max_t(int, nlmsg_len(nlh) - NLMSG_ALIGN(hdrlen), 0);
 }
 
 /** @} */