diff options
author | Thomas Haller <thaller@redhat.com> | 2021-08-10 17:14:04 +0200 |
---|---|---|
committer | Thomas Haller <thaller@redhat.com> | 2021-08-17 13:18:07 +0200 |
commit | 68a5d1cfe5126241892fc26736daad2c5b5f553d (patch) | |
tree | 2378e0d50f4145c2433826455e2ea657d257376a | |
parent | 6f1274caeab6a0113cad60d2ab9b681ffae43e8b (diff) | |
download | NetworkManager-68a5d1cfe5126241892fc26736daad2c5b5f553d.tar.gz |
platform/netlink: refactor handling length in validate_nla()
-rw-r--r-- | src/libnm-platform/nm-netlink.c | 9 |
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; } |