dirmngr: Do not use brackets around legacy IP addresses.

* dirmngr/ks-engine-hkp.c (my_getnameinfo): Change args to take a
complete addrinfo.  Bracket only v6 addresses.  Change caller.
This commit is contained in:
Werner Koch 2014-03-14 16:22:54 +01:00
parent a401f768ca
commit d7fbefeb82
1 changed files with 14 additions and 9 deletions

View File

@ -214,23 +214,29 @@ select_random_host (int *table)
for TMPHOST which is 2 bytes larger than the the largest hostname. for TMPHOST which is 2 bytes larger than the the largest hostname.
returns 0 on success or an EAI error code. */ returns 0 on success or an EAI error code. */
static int static int
my_getnameinfo (const struct sockaddr *sa, socklen_t salen, my_getnameinfo (struct addrinfo *ai, char *host, size_t hostlen)
char *host, size_t hostlen)
{ {
int ec; int ec;
char *p;
if (hostlen < 5) if (hostlen < 5)
return EAI_OVERFLOW; return EAI_OVERFLOW;
ec = getnameinfo (sa, salen, host, hostlen, NULL, 0, NI_NAMEREQD); ec = getnameinfo (ai->ai_addr, ai->ai_addrlen,
host, hostlen, NULL, 0, NI_NAMEREQD);
if (!ec && *host == '[') if (!ec && *host == '[')
ec = EAI_FAIL; /* A name may never start with a bracket. */ ec = EAI_FAIL; /* A name may never start with a bracket. */
else if (ec == EAI_NONAME) else if (ec == EAI_NONAME)
{ {
*host = '['; p = host;
ec = getnameinfo (sa, salen, host + 1, hostlen - 2, if (ai->ai_family == AF_INET6)
NULL, 0, NI_NUMERICHOST); {
if (!ec) *p++ = '[';
hostlen -= 2;
}
ec = getnameinfo (ai->ai_addr, ai->ai_addrlen,
p, hostlen, NULL, 0, NI_NUMERICHOST);
if (!ec && ai->ai_family == AF_INET6)
strcat (host, "]"); strcat (host, "]");
} }
@ -295,8 +301,7 @@ map_host (ctrl_t ctrl, const char *name, int force_reselect)
continue; continue;
dirmngr_tick (ctrl); dirmngr_tick (ctrl);
if ((ec = my_getnameinfo (ai->ai_addr, ai->ai_addrlen, if ((ec = my_getnameinfo (ai, tmphost, sizeof tmphost)))
tmphost, sizeof tmphost)))
{ {
log_info ("getnameinfo failed while checking '%s': %s\n", log_info ("getnameinfo failed while checking '%s': %s\n",
name, gai_strerror (ec)); name, gai_strerror (ec));