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().
This commit is contained in:
Thomas Haller 2019-02-18 10:05:40 +01:00
parent af13eb6cac
commit fac357ac8b
2 changed files with 9 additions and 13 deletions

View file

@ -366,18 +366,6 @@ nlmsg_put (struct nl_msg *n, uint32_t pid, uint32_t seq,
return nlh;
}
uint64_t
nla_get_u64 (const struct nlattr *nla)
{
uint64_t tmp = 0;
if ( nla
&& nla_len (nla) >= sizeof (tmp))
memcpy (&tmp, nla_data (nla), sizeof (tmp));
return tmp;
}
size_t
nla_strlcpy (char *dst,
const struct nlattr *nla,

View file

@ -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)