X-Git-Url: http://git.archive.openwrt.org/?p=project%2Fodhcpd.git;a=blobdiff_plain;f=src%2Fndp.c;h=e006c85261af4180147fb6b79b1d37a95f7a8e99;hp=6d18bb5bae5e9e135dce833c6e8770c3268fc88b;hb=56c6a4a72a0e086074f69d2ee5cc46079d179dac;hpb=e9a21fdb43c9f94762a724db1a043b376f745ae3 diff --git a/src/ndp.c b/src/ndp.c index 6d18bb5..e006c85 100644 --- a/src/ndp.c +++ b/src/ndp.c @@ -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); }