platform/netlink: cleanup handling of nla_attr_minlen

- make nla_attr_minlen[] and array of uint8_t. That is large enough for
  all values we have.

- don't handle NLA_UNSPEC specially. nla_attr_minlen[NLA_UNSPEC] returns
  zero just fine.
This commit is contained in:
Thomas Haller 2021-08-10 16:37:28 +02:00
parent 0adc4fc4f6
commit 386b367bfa
No known key found for this signature in database
GPG key ID: 29C2366E4DFC5728

View file

@ -585,21 +585,20 @@ nla_nest_end(struct nl_msg *msg, struct nlattr *start)
return _nest_end(msg, start, 0);
}
static const uint16_t nla_attr_minlen[NLA_TYPE_MAX + 1] = {
static const uint8_t nla_attr_minlen[NLA_TYPE_MAX + 1] = {
[NLA_U8] = sizeof(uint8_t),
[NLA_U16] = sizeof(uint16_t),
[NLA_U32] = sizeof(uint32_t),
[NLA_U64] = sizeof(uint64_t),
[NLA_STRING] = 1,
[NLA_FLAG] = 0,
};
static int
validate_nla(const struct nlattr *nla, int maxtype, const struct nla_policy *policy)
{
const struct nla_policy *pt;
unsigned int minlen = 0;
int type = nla_type(nla);
uint16_t minlen;
int type = nla_type(nla);
if (type < 0 || type > maxtype)
return 0;
@ -611,7 +610,7 @@ validate_nla(const struct nlattr *nla, int maxtype, const struct nla_policy *pol
if (pt->minlen)
minlen = pt->minlen;
else if (pt->type != NLA_UNSPEC)
else
minlen = nla_attr_minlen[pt->type];
if (nla_len(nla) < minlen)