summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2021-08-10 17:14:04 +0200
committerThomas Haller <thaller@redhat.com>2021-08-17 13:18:07 +0200
commit68a5d1cfe5126241892fc26736daad2c5b5f553d (patch)
tree2378e0d50f4145c2433826455e2ea657d257376a
parent6f1274caeab6a0113cad60d2ab9b681ffae43e8b (diff)
downloadNetworkManager-68a5d1cfe5126241892fc26736daad2c5b5f553d.tar.gz
platform/netlink: refactor handling length in validate_nla()
-rw-r--r--src/libnm-platform/nm-netlink.c9
1 files changed, 6 insertions, 3 deletions
diff --git a/src/libnm-platform/nm-netlink.c b/src/libnm-platform/nm-netlink.c
index efe41bca07..d836e4c9ff 100644
--- a/src/libnm-platform/nm-netlink.c
+++ b/src/libnm-platform/nm-netlink.c
@@ -598,6 +598,7 @@ validate_nla(const struct nlattr *nla, int maxtype, const struct nla_policy *pol
{
const struct nla_policy *pt;
uint16_t minlen;
+ uint16_t len;
int type = nla_type(nla);
if (type < 0 || type > maxtype)
@@ -613,10 +614,12 @@ validate_nla(const struct nlattr *nla, int maxtype, const struct nla_policy *pol
else
minlen = nla_attr_minlen[pt->type];
- if (nla_len(nla) < minlen)
+ len = nla_len(nla);
+
+ if (len < minlen)
return -NME_UNSPEC;
- if (pt->maxlen && nla_len(nla) > pt->maxlen)
+ if (pt->maxlen && len > pt->maxlen)
return -NME_UNSPEC;
if (pt->type == NLA_STRING) {
@@ -625,7 +628,7 @@ validate_nla(const struct nlattr *nla, int maxtype, const struct nla_policy *pol
nm_assert(minlen > 0);
data = nla_data(nla);
- if (data[nla_len(nla) - 1] != '\0')
+ if (data[len - 1u] != '\0')
return -NME_UNSPEC;
}