diff options
author | Hans Dedecker <dedeckeh@gmail.com> | 2016-02-01 10:56:23 +0100 |
---|---|---|
committer | Felix Fietkau <nbd@openwrt.org> | 2016-02-01 11:09:57 +0100 |
commit | 2bd3327f35266dc284ab309ea5ed2008d8b40374 (patch) | |
tree | b5855e1b1174df894dfb59fa29084f489f17e40a /interface-ip.c | |
parent | b998775b925330725e547af8d33394db0d638f7a (diff) |
interface-ip: Fix possbile segfaults
Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
Diffstat (limited to 'interface-ip.c')
-rw-r--r-- | interface-ip.c | 25 |
1 files changed, 18 insertions, 7 deletions
diff --git a/interface-ip.c b/interface-ip.c index 919c8cc..eb585f5 100644 --- a/interface-ip.c +++ b/interface-ip.c @@ -366,7 +366,7 @@ interface_ip_add_route(struct interface *iface, struct blob_attr *attr, bool v6) const char *mask = strtok_r(NULL, "/", &saveptr); if (!addr || inet_pton(af, addr, &route->source) < 1) { - DPRINTF("Failed to parse route source: %s\n", addr); + DPRINTF("Failed to parse route source: %s\n", addr ? addr : "NULL"); goto error; } @@ -857,6 +857,9 @@ static void interface_update_prefix_assignments(struct device_prefix *prefix, bo // End-of-assignment sentinel c = malloc(sizeof(*c) + 1); + if (!c) + return; + c->assigned = 1 << (64 - prefix->length); c->length = 64; c->name[0] = 0; @@ -867,12 +870,14 @@ static void interface_update_prefix_assignments(struct device_prefix *prefix, bo if (prefix->excl_length > 0) { const char name[] = "!excluded"; c = malloc(sizeof(*c) + sizeof(name)); - c->assigned = ntohl(prefix->excl_addr.s6_addr32[1]) & - ((1 << (64 - prefix->length)) - 1); - c->length = prefix->excl_length; - c->addr = in6addr_any; - memcpy(c->name, name, sizeof(name)); - list_add(&c->head, &prefix->assignments); + if (c) { + c->assigned = ntohl(prefix->excl_addr.s6_addr32[1]) & + ((1 << (64 - prefix->length)) - 1); + c->length = prefix->excl_length; + c->addr = in6addr_any; + memcpy(c->name, name, sizeof(name)); + list_add(&c->head, &prefix->assignments); + } } bool assigned_any = false; @@ -900,6 +905,9 @@ static void interface_update_prefix_assignments(struct device_prefix *prefix, bo size_t namelen = strlen(iface->name) + 1; c = malloc(sizeof(*c) + namelen); + if (!c) + continue; + c->length = iface->assignment_length; c->assigned = iface->assignment_hint; c->addr = in6addr_any; @@ -1033,6 +1041,9 @@ interface_ip_add_device_prefix(struct interface *iface, struct in6_addr *addr, pclass = (iface) ? iface->name : "local"; struct device_prefix *prefix = calloc(1, sizeof(*prefix) + strlen(pclass) + 1); + if (!prefix) + return NULL; + prefix->length = length; prefix->addr = *addr; prefix->preferred_until = preferred_until; |