Make sure to return a proper string in ai_canonname.
authorflorian <florian@openbsd.org>
Mon, 15 Jan 2024 18:03:39 +0000 (18:03 +0000)
committerflorian <florian@openbsd.org>
Mon, 15 Jan 2024 18:03:39 +0000 (18:03 +0000)
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

lib/libc/asr/getaddrinfo_async.c

index a1282e7..23262f5 100644 (file)
@@ -1,4 +1,4 @@
-/*     $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>
  *
@@ -258,7 +258,8 @@ getaddrinfo_async_run(struct asr_query *as, struct asr_result *ar)
                                            !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;
                                }