summaryrefslogtreecommitdiffstats
path: root/lib/route
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2017-10-23 09:25:44 (GMT)
committerThomas Haller <thaller@redhat.com>2017-10-23 10:10:30 (GMT)
commit7ec0fae0df54d4bff4a45bae9a18519e8c03fa89 (patch)
tree9001d8ea3c906dcad833dfc8cd42e1536b707ada /lib/route
parentf9d68741065182f4c75a17426246f12a4aeb3c56 (diff)
downloadlibnl-7ec0fae0df54d4bff4a45bae9a18519e8c03fa89.zip
libnl-7ec0fae0df54d4bff4a45bae9a18519e8c03fa89.tar.gz
libnl-7ec0fae0df54d4bff4a45bae9a18519e8c03fa89.tar.bz2
route/vlan: grow buffer exponentially in rtnl_link_vlan_set_egress_map()
By a factor of 1.5 instead of 2, to value wasted storage overhead higher then the number of operations. Also, check for integer overflows.
Diffstat (limited to 'lib/route')
-rw-r--r--lib/route/link/vlan.c10
1 files changed, 8 insertions, 2 deletions
diff --git a/lib/route/link/vlan.c b/lib/route/link/vlan.c
index 23fdf66..7c5aa06 100644
--- a/lib/route/link/vlan.c
+++ b/lib/route/link/vlan.c
@@ -595,10 +595,16 @@ int rtnl_link_vlan_set_egress_map(struct rtnl_link *link, uint32_t from, int to)
return -NLE_INVAL;
if (vi->vi_negress >= vi->vi_egress_size) {
- int new_size = vi->vi_egress_size + 32;
+ uint32_t new_size = vi->vi_egress_size + 1 + vi->vi_egress_size / 2;
+ size_t bytes;
void *ptr;
- ptr = realloc(vi->vi_egress_qos, new_size * sizeof(struct vlan_map));
+ if (new_size < vi->vi_egress_size)
+ return -NLE_NOMEM;
+ bytes = (size_t) new_size * sizeof(struct vlan_map);
+ if (bytes / sizeof (struct vlan_map) != new_size)
+ return -NLE_NOMEM;
+ ptr = realloc(vi->vi_egress_qos, bytes);
if (!ptr)
return -NLE_NOMEM;