From 01cfa9c1dbe8215717e27aa6802290cf51ab6186 Mon Sep 17 00:00:00 2001 From: Thomas Graf Date: Thu, 27 Jun 2013 18:29:17 +0200 Subject: [PATCH] msg: Avoid returning a negative value for nlmsg_attrlen() 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 --- lib/msg.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/msg.c b/lib/msg.c index 6478507..3c58cb7 100644 --- 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); } /** @} */