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>
*/
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);
}
/** @} */