[PATCH 1/1] attr: nla_get_u64() should return 0 if the attribute does not fully contain 64 bit

Thomas Haller thaller at redhat.com
Wed Jun 25 01:11:56 PDT 2014


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. Also considering endianness, reading a truncated integer
does not seem to be useful and should result in a defined behavior
instead.

Signed-off-by: Thomas Haller <thaller at redhat.com>
---
 lib/attr.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/lib/attr.c b/lib/attr.c
index d3de399..d1f0268 100644
--- a/lib/attr.c
+++ b/lib/attr.c
@@ -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;
 }
-- 
1.9.3




More information about the libnl mailing list