netresolv: Merge a patch to getaddrinfo from NetBSD.

This block was originally disabled in libbind, and we enabled it
independently; and so did NetBSD. But they also made one other
fix:

From: christos <christos@netbsd.org>
Date: Thu, 28 Dec 2017 15:12:15 +0000
Subject: [PATCH] PR/52837: Michael Kaufmann: getaddrinfo() resolves "127.0.0.1
 www.example.com" to 127.0.0.1. Apply the patch from FreeBSD and explain the
 rationale.
This commit is contained in:
Augustin Cavalier 2018-08-01 17:34:32 -04:00
parent c9431a6752
commit b3b69f8178

View File

@ -807,7 +807,22 @@ explore_numeric(const struct addrinfo *pai, const char *hostname,
switch (afd->a_af) {
case AF_INET:
if (inet_aton(hostname, (struct in_addr *)pton) == 1) {
/*
* RFC3493 section 6.1, requires getaddrinfo() to accept
* AF_INET formats that are accepted by inet_addr(); here
* we use the equivalent inet_aton() function so we can
* check for errors. inet_pton() only accepts addresses
* in the dotted quad format and only in base 10, so we
* need to treat AF_INET specially.
*
* We also check for trailing characters and fail if there
* are any. This matches the inet_pton6(), but not the
* inet_pton4() behavior. We choose to make the protocol
* behavior consistent.
*/
if (inet_aton(hostname, (void *)pton) == 1 &&
hostname[strspn(hostname, "0123456789.xabcdefXABCDEF")]
== '\0') {
if (pai->ai_family == afd->a_af ||
pai->ai_family == PF_UNSPEC /*?*/) {
GET_AI(cur->ai_next, afd, pton);