diff options
author | Hans Dedecker <dedeckeh@gmail.com> | 2014-02-22 09:22:37 +0100 |
---|---|---|
committer | Steven Barth <steven@midlink.org> | 2014-02-25 12:08:24 +0100 |
commit | 56c6a4a72a0e086074f69d2ee5cc46079d179dac (patch) | |
tree | 61e4b7495ada0458cc763d1586bf6ccfdcaa0304 /src | |
parent | d21af09a10de15f340b5bbd05ddf0603dae0584e (diff) |
Fix parsing of static ndp entries
Diffstat (limited to 'src')
-rw-r--r-- | src/ndp.c | 15 |
1 files changed, 12 insertions, 3 deletions
@@ -167,6 +167,7 @@ int setup_ndp_interface(struct interface *iface, bool enable) memcpy(entry, iface->static_ndp, iface->static_ndp_len); for (entry = strtok_r(entry, " ", &saveptr); entry; entry = strtok_r(NULL, " ", &saveptr)) { + char *sep; struct ndp_neighbor *n = malloc(sizeof(*n)); if (!n) { syslog(LOG_ERR, "Malloc failed for static NDP-prefix %s", entry); @@ -176,12 +177,20 @@ int setup_ndp_interface(struct interface *iface, bool enable) n->iface = iface; n->timeout = 0; - char ipbuf[INET6_ADDRSTRLEN]; - if (sscanf(entry, "%45s/%hhu", ipbuf, &n->len) < 2 - || n->len > 128 || inet_pton(AF_INET6, ipbuf, &n->addr) != 1) { + sep = strchr(entry, '/'); + if (!sep) { + free(n); syslog(LOG_ERR, "Invalid static NDP-prefix %s", entry); return -1; } + + *sep = 0; + n->len = atoi(sep + 1); + if (inet_pton(AF_INET6, entry, &n->addr) != 1 || n->len > 128) { + free(n); + syslog(LOG_ERR, "Invalid static NDP-prefix %s/%s", entry, sep + 1); + return -1; + } list_add(&n->head, &neighbors); } |