When we made sure that getaddrinfo(3) always resolves "localhost" to
the loopback address we forgot to set ai_canonname if AI_CANONNAME or
AI_FQDN is set. On a successful call ai_canonname has to be a NUL-terminated
string if either of those flags are set.
Problem observed by a@alexis-fouilhe.fr in smtpd(8) with a hostname of
"localhost".
OK millert
-/* $OpenBSD: getaddrinfo_async.c,v 1.61 2023/11/21 15:26:56 florian Exp $ */
+/* $OpenBSD: getaddrinfo_async.c,v 1.62 2024/01/15 18:03:39 florian Exp $ */
/*
* Copyright (c) 2012 Eric Faurot <eric@openbsd.org>
*
!is_localhost) ? "::" : "::1";
/* This can't fail */
_asr_sockaddr_from_str(&sa.sa, family, str);
- if ((r = addrinfo_add(as, &sa.sa, NULL))) {
+ if ((r = addrinfo_add(as, &sa.sa,
+ "localhost."))) {
ar->ar_gai_errno = r;
break;
}