From 30a2e20cccb10e8865ca3b75c381bb5411e5f603 Mon Sep 17 00:00:00 2001 From: Roy Marples Date: Fri, 7 Feb 2020 12:52:51 +0000 Subject: [PATCH] options: Improve AF_INET6 address parsing and logging --- src/if-options.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/if-options.c b/src/if-options.c index f922cfc1..ccfb2a7e 100644 --- a/src/if-options.c +++ b/src/if-options.c @@ -1165,7 +1165,7 @@ parse_option(struct dhcpcd_ctx *ctx, const char *ifname, struct if_options *ifo, np = strchr(p, '/'); if (np) *np++ = '\0'; - if (inet_pton(AF_INET6, p, &ifo->req_addr6) == 1) { + if ((i = inet_pton(AF_INET6, p, &ifo->req_addr6)) == 1) { if (np) { ifo->req_prefix_len = (uint8_t)strtou(np, NULL, 0, 0, 128, &e); @@ -1178,6 +1178,14 @@ parse_option(struct dhcpcd_ctx *ctx, const char *ifname, struct if_options *ifo, } else ifo->req_prefix_len = 128; } + if (np) + *(--np) = '\0'; + if (i != 1) { + logerrx("invalid AF_INET6: %s", p); + memset(&ifo->req_addr6, 0, + sizeof(ifo->req_addr6)); + return -1; + } } else add_environ(&ifo->config, arg, 1); break; @@ -1398,8 +1406,8 @@ parse_option(struct dhcpcd_ctx *ctx, const char *ifname, struct if_options *ifo, p = strchr(arg, '/'); if (p) *p++ = '\0'; - if (inet_pton(AF_INET6, arg, &ia->addr) == -1) { - logerr("%s", arg); + if (inet_pton(AF_INET6, arg, &ia->addr) != 1) { + logerrx("invalid AF_INET6: %s", arg); memset(&ia->addr, 0, sizeof(ia->addr)); } if (p && ia->ia_type == D6_OPTION_IA_PD) { -- 2.47.2