diff options
author | Thomas Haller <thaller@redhat.com> | 2019-02-18 10:05:40 +0100 |
---|---|---|
committer | Thomas Haller <thaller@redhat.com> | 2019-02-22 09:58:09 +0100 |
commit | fac357ac8b299af9f042d5303400da16a0244bc2 (patch) | |
tree | 7059767af98632906506e9404a6d4719240034ef /src/platform/nm-netlink.h | |
parent | af13eb6cacdaac447837d6cd53df04cc4a6b7e05 (diff) |
platform/netlink: require valid nla argument for nla_get_u64()
nla_get_u64() was unlike all other nla_get_u*() implementations, in that it
would allow for a missing/invalid nla argument, and return 0.
Don't do this. For one, don't behave different than other getters.
Also, there really is no space to report errors. Hence, the caller must
make sure that the attribute is present and suitable -- like for other
nla_get_*() functions.
None of the callers relied on being able to pass NULL attribute.
Also, inline the function and use unaligned_read_ne64(). That is our
preferred way for reading unaligned data, not memcpy().
Diffstat (limited to 'src/platform/nm-netlink.h')
-rw-r--r-- | src/platform/nm-netlink.h | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/src/platform/nm-netlink.h b/src/platform/nm-netlink.h index 3c2c784ad6..840e56d8e4 100644 --- a/src/platform/nm-netlink.h +++ b/src/platform/nm-netlink.h @@ -25,6 +25,8 @@ #include <linux/rtnetlink.h> #include <linux/genetlink.h> +#include "nm-utils/unaligned.h" + /*****************************************************************************/ #define NLMSGERR_ATTR_UNUSED 0 @@ -201,7 +203,13 @@ nla_get_s32 (const struct nlattr *nla) return *((const int32_t *) nla_data (nla)); } -uint64_t nla_get_u64 (const struct nlattr *nla); +static inline uint64_t +nla_get_u64 (const struct nlattr *nla) +{ + nm_assert (nla_len (nla) >= sizeof (uint64_t)); + + return unaligned_read_ne64 (nla_data (nla)); +} static inline char * nla_get_string (const struct nlattr *nla) |