summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2017-01-18 10:59:23 (GMT)
committerThomas Haller <thaller@redhat.com>2017-01-18 11:30:26 (GMT)
commitc473d59f972c35c5a7363d52ee6ee1e0792de0f8 (patch)
treed3ef81aa879df490138eeca14f2c98ceb75f4483 /lib
parent64b12a065ae4fb84ae92299037c7eb8526549c85 (diff)
downloadlibnl-c473d59f972c35c5a7363d52ee6ee1e0792de0f8.zip
libnl-c473d59f972c35c5a7363d52ee6ee1e0792de0f8.tar.gz
libnl-c473d59f972c35c5a7363d52ee6ee1e0792de0f8.tar.bz2
lib/attr.c: check for valid length argument in nla_reserve()
https://github.com/thom311/libnl/issues/124
Diffstat (limited to 'lib')
-rw-r--r--lib/attr.c11
1 files changed, 9 insertions, 2 deletions
diff --git a/lib/attr.c b/lib/attr.c
index a3d1b16..0dca3ec 100644
--- a/lib/attr.c
+++ b/lib/attr.c
@@ -457,7 +457,10 @@ struct nlattr *nla_reserve(struct nl_msg *msg, int attrtype, int attrlen)
{
struct nlattr *nla;
int tlen;
-
+
+ if (attrlen < 0)
+ return NULL;
+
tlen = NLMSG_ALIGN(msg->nm_nlh->nlmsg_len) + nla_total_size(attrlen);
if (tlen > msg->nm_size)
@@ -499,8 +502,12 @@ int nla_put(struct nl_msg *msg, int attrtype, int datalen, const void *data)
struct nlattr *nla;
nla = nla_reserve(msg, attrtype, datalen);
- if (!nla)
+ if (!nla) {
+ if (datalen < 0)
+ return -NLE_INVAL;
+
return -NLE_NOMEM;
+ }
if (datalen > 0) {
memcpy(nla_data(nla), data, datalen);