]> git.ipfire.org Git - thirdparty/libnl.git/commitdiff
attr: nla_get_u64() should return 0 if the attribute does not fully contain 64 bit
authorThomas Haller <thaller@redhat.com>
Wed, 25 Jun 2014 08:11:56 +0000 (10:11 +0200)
committerThomas Haller <thaller@redhat.com>
Wed, 25 Jun 2014 10:37:58 +0000 (12:37 +0200)
Manually "inline" nla_memcpy() to nla_get_u64() and change the behavior
to return always zero (0) if the attribute does not contain at least
sizeof(uint64_t) bytes. Considering endianness, reading a truncated integer
does not seem to be useful and should result in a defined behavior
instead.

Acked-by: Thomas Graf <tgraf@suug.ch>
Signed-off-by: Thomas Haller <thaller@redhat.com>
lib/attr.c

index d3de3993b823362a1a742148dec423d1f9a79c4d..d1f0268e4dcb3a919bb6e5f6a74df4f0665e09fd 100644 (file)
@@ -650,7 +650,8 @@ uint64_t nla_get_u64(struct nlattr *nla)
 {
        uint64_t tmp = 0;
 
-       nla_memcpy(&tmp, nla, sizeof(tmp));
+       if (nla && nla_len(nla) >= sizeof(tmp))
+               memcpy(&tmp, nla_data(nla), sizeof(tmp));
 
        return tmp;
 }