changeset 5050:fb4b6e3ab45e draft

options: Improve AF_INET6 address parsing and logging
author Roy Marples <roy@marples.name>
date Fri, 07 Feb 2020 12:52:51 +0000
parents 1d342610ff74
children 5f9bca74bad0
files src/if-options.c
diffstat 1 files changed, 11 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/src/if-options.c	Fri Feb 07 12:18:46 2020 +0000
+++ b/src/if-options.c	Fri Feb 07 12:52:51 2020 +0000
@@ -1166,7 +1166,7 @@
 			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);
@@ -1179,6 +1179,14 @@
 				} 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;
@@ -1427,8 +1435,8 @@
 				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) {