I went through the tree and found these uneeded checks.
They are unneeded because either:
- we are asking getaddrinfo for a specific AF and shove the result
into the right sized sockaddr_in{,6}
- we are asking for AF_UNSPEC and switch on the returned ai_family
- we stuff the result into sockaddr_storage which is guaranteed
to be large enough
The checks in radiusd and switchd are necessary since they either
use a union or struct sockaddr.
Triggered by kn@'s ping(8) observation.
OK?
diff --git sbin/ifconfig/ifconfig.c sbin/ifconfig/ifconfig.c
index bde6d15f165..6d78d863190 100644
--- sbin/ifconfig/ifconfig.c
+++ sbin/ifconfig/ifconfig.c
@@ -3542,10 +3542,6 @@ settunnel(const char *src, const char *dst)
errx(1,
"source and destination address families do not match");
- if (srcres->ai_addrlen > sizeof(req.addr) ||
- dstres->ai_addrlen > sizeof(req.dstaddr))
- errx(1, "invalid sockaddr");
-
memset(&req, 0, sizeof(req));
(void) strlcpy(req.iflr_name, name, sizeof(req.iflr_name));
memcpy(&req.addr, srcres->ai_addr, srcres->ai_addrlen);
@@ -5879,8 +5875,6 @@ in6_getaddr(const char *s, int which)
error = getaddrinfo(s, "0", &hints, &res);
if (error)
errx(1, "%s: %s", s, gai_strerror(error));
- if (res->ai_addrlen != sizeof(struct sockaddr_in6))
- errx(1, "%s: bad value", s);
memcpy(sin6, res->ai_addr, res->ai_addrlen);
#ifdef __KAME__
if (IN6_IS_ADDR_LINKLOCAL(&sin6->sin6_addr) &&
diff --git sbin/route/route.c sbin/route/route.c
index e255fd6ec6f..909796e3951 100644
--- sbin/route/route.c
+++ sbin/route/route.c
@@ -866,8 +866,6 @@ getaddr(int which, int af, char *s, struct hostent **hpp)
if (getaddrinfo(buf, "0", &hints, &res) != 0)
errx(1, "%s: bad value", s);
}
- if (sizeof(su->sin6) != res->ai_addrlen)
- errx(1, "%s: bad value", s);
if (res->ai_next)
errx(1, "%s: resolved to multiple values", s);
memcpy(&su->sin6, res->ai_addr, sizeof(su->sin6));
diff --git usr.bin/ssh/sshconnect.c usr.bin/ssh/sshconnect.c
index 47b261f74ea..b16659061c6 100644
--- usr.bin/ssh/sshconnect.c
+++ usr.bin/ssh/sshconnect.c
@@ -352,10 +352,6 @@ ssh_create_socket(struct addrinfo *ai)
error("getaddrinfo: no addrs");
goto fail;
}
- if (res->ai_addrlen > sizeof(bindaddr)) {
- error("%s: addr doesn't fit", __func__);
- goto fail;
- }
memcpy(&bindaddr, res->ai_addr, res->ai_addrlen);
bindaddrlen = res->ai_addrlen;
} else if (options.bind_interface != NULL) {
diff --git usr.sbin/inetd/inetd.c usr.sbin/inetd/inetd.c
index fce5fa658d7..363de1bf709 100644
--- usr.sbin/inetd/inetd.c
+++ usr.sbin/inetd/inetd.c
@@ -1248,9 +1248,6 @@ more:
continue;
}
for (res = res0; res; res = res->ai_next) {
- if (res->ai_addrlen >
- sizeof(sep->se_ctrladdr_storage))
- continue;
/*
* If sep is unused, store host in there.
* Otherwise, dup a new entry and prepend it.
diff --git usr.sbin/iscsictl/parser.c usr.sbin/iscsictl/parser.c
index 2dbde985456..e8248f64274 100644
--- usr.sbin/iscsictl/parser.c
+++ usr.sbin/iscsictl/parser.c
@@ -235,8 +235,6 @@ parse_addr(const char *word, struct sockaddr_storage *sa)
hints.ai_protocol = IPPROTO_TCP;
if ((rv = getaddrinfo(word, "iscsi", &hints, &addrs)) == 0) {
- if (sizeof(*sa) < addrs->ai_addrlen)
- err(1, "parse_host: bork bork bork");
bcopy(addrs->ai_addr, sa, addrs->ai_addrlen);
freeaddrinfo(addrs);
return (0);
diff --git usr.sbin/switchctl/parser.c usr.sbin/switchctl/parser.c
index adb42f33ce9..69182db98ab 100644
--- usr.sbin/switchctl/parser.c
+++ usr.sbin/switchctl/parser.c
@@ -273,10 +273,6 @@ parse_addr(const char *word, struct sockaddr_storage *ss)
hints.ai_family = PF_UNSPEC;
hints.ai_flags = AI_NUMERICHOST;
if (getaddrinfo(word, "0", &hints, &ai) == 0) {
- if (ai->ai_addrlen > sizeof(*ss)) {
- warnx("invalid address length");
- return (-1);
- }
memcpy(ss, ai->ai_addr, ai->ai_addrlen);
ss->ss_len = ai->ai_addrlen;
freeaddrinfo(ai);
@@ -290,10 +286,6 @@ parse_addr(const char *word, struct sockaddr_storage *ss)
hints.ai_flags = AI_ADDRCONFIG;
if (getaddrinfo(word, "0", &hints, &ai) == 0) {
/* Pick first name only */
- if (ai->ai_addrlen > sizeof(*ss)) {
- warnx("invalid address length");
- return (-1);
- }
memcpy(ss, ai->ai_addr, ai->ai_addrlen);
ss->ss_len = ai->ai_addrlen;
freeaddrinfo(ai);
diff --git usr.sbin/traceroute/traceroute.c usr.sbin/traceroute/traceroute.c
index 96a0bd15aa9..ec737e30d20 100644
--- usr.sbin/traceroute/traceroute.c
+++ usr.sbin/traceroute/traceroute.c
@@ -588,16 +588,10 @@ main(int argc, char *argv[])
switch (res->ai_family) {
case AF_INET:
- if (res->ai_addrlen != sizeof(to4))
- errx(1, "size of sockaddr mismatch");
-
to = (struct sockaddr *)&to4;
from = (struct sockaddr *)&from4;
break;
case AF_INET6:
- if (res->ai_addrlen != sizeof(to6))
- errx(1, "size of sockaddr mismatch");
-
to = (struct sockaddr *)&to6;
from = (struct sockaddr *)&from6;
break;
@@ -779,8 +773,6 @@ main(int argc, char *argv[])
&res)))
errx(1, "%s: %s", conf->source,
gai_strerror(error));
- if (res->ai_addrlen != sizeof(from6))
- errx(1, "size of sockaddr mismatch");
memcpy(&from6, res->ai_addr, res->ai_addrlen);
freeaddrinfo(res);
} else {
--
I'm not entirely sure you are real.