summaryrefslogtreecommitdiff
path: root/lib/msg.c
diff options
context:
space:
mode:
authorThomas Graf <tgraf@suug.ch>2013-06-27 18:29:17 +0200
committerThomas Graf <tgraf@suug.ch>2013-06-27 18:29:17 +0200
commit01cfa9c1dbe8215717e27aa6802290cf51ab6186 (patch)
treed1a8e18e003075789fef17fd06640acd2b54fa75 /lib/msg.c
parentd612180cda43606425c3476e13a6076b6271d27a (diff)
downloadlibnl-01cfa9c1dbe8215717e27aa6802290cf51ab6186.tar.gz
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 <tgraf@suug.ch>
Diffstat (limited to 'lib/msg.c')
-rw-r--r--lib/msg.c2
1 files changed, 1 insertions, 1 deletions
diff --git a/lib/msg.c b/lib/msg.c
index 6478507c..3c58cb7c 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);
}
/** @} */