]> git.ipfire.org Git - thirdparty/libnl.git/commitdiff
Patch for unexpectedly aligned messages
authorMarc de Kruijf <mdekruijf@gmail.com>
Wed, 26 Aug 2009 21:28:01 +0000 (16:28 -0500)
committerThomas Graf <tgr@lsx.localdomain>
Wed, 2 Sep 2009 16:43:03 +0000 (18:43 +0200)
I found the following bug, where nlmsg_ok() in lib/msg.c would
incorrectly return 'true' when the input argument 'remaining' was a negative
number.  This happens when the message is not aligned the way that libnl
expects (although it is still legal).

In the comparison of the signed and unsigned numbers on line 284, the signed
number gets converted to an unsigned number, which is unexpected and
naturally produces a bug.  My patch is below.  The cast is ugly, but it
fixes the problem.

lib/msg.c

index 22761a09a98c95449fe797236e579a8e4bfe8e03..9fe9d5418c06b5523a273e9b4ebb6c1f3b68268b 100644 (file)
--- a/lib/msg.c
+++ b/lib/msg.c
@@ -284,7 +284,7 @@ int nlmsg_valid_hdr(const struct nlmsghdr *nlh, int hdrlen)
  */
 int nlmsg_ok(const struct nlmsghdr *nlh, int remaining)
 {
-       return (remaining >= sizeof(struct nlmsghdr) &&
+       return (remaining >= (int)sizeof(struct nlmsghdr) &&
                nlh->nlmsg_len >= sizeof(struct nlmsghdr) &&
                nlh->nlmsg_len <= remaining);
 }