On Sat, Oct 13, 2018 at 08:29:34PM +0200, Klemens Nanni wrote:
> After calling getaddrinfo(3) we check the size of the returned socket
> address to match for AF-specific cases, but I fail to see how this is
> even possible.
>
> `hints.ai_family' is set appropiately and `res->ai_family' is checked,
> so `res->ai_addrlen' is guaranteed to be correct.
>
> It seems like this is a leftover from before florian@ reworked ping
> to use getaddrinfo(3) and eventually merged it with ping6.
Indeed, IIRC this came from ping6 which was much more paranoid about
these kind of things.
In this day and age we can trust the libc resolver to do the right
thing. If not, why do we trust it to give us the correct family but
not the correct size?
OK florian
>
> None of my test scenarios could trigger this error.
> Do I miss something here or is this OK to remove?
>
> Index: ping.c
> ===================================================================
> RCS file: /cvs/src/sbin/ping/ping.c,v
> retrieving revision 1.228
> diff -u -p -r1.228 ping.c
> --- ping.c 21 Jul 2018 07:27:54 -0000 1.228
> +++ ping.c 13 Oct 2018 18:14:00 -0000
> @@ -449,14 +449,10 @@ main(int argc, char *argv[])
>
> switch (res->ai_family) {
> case AF_INET:
> - if (res->ai_addrlen != sizeof(dst4))
> - errx(1, "size of sockaddr mismatch");
> dst = (struct sockaddr *)&dst4;
> from = (struct sockaddr *)&from4;
> break;
> case AF_INET6:
> - if (res->ai_addrlen != sizeof(dst6))
> - errx(1, "size of sockaddr mismatch");
> dst = (struct sockaddr *)&dst6;
> from = (struct sockaddr *)&from6;
> break;
> @@ -488,8 +484,6 @@ main(int argc, char *argv[])
> hints.ai_family = dst->sa_family;
> if ((error = getaddrinfo(source, NULL, &hints, &res)))
> errx(1, "%s: %s", source, gai_strerror(error));
> - if (res->ai_addrlen != dst->sa_len)
> - errx(1, "size of sockaddr mismatch");
> memcpy(from, res->ai_addr, res->ai_addrlen);
> freeaddrinfo(res);
>
>
--
I'm not entirely sure you are real.