From fada2b0bd226843a6444c75947c346f81ce1fa83 Mon Sep 17 00:00:00 2001 From: florian Date: Tue, 21 Nov 2023 15:26:56 +0000 Subject: [PATCH] Do not short-circuit localhost resolution when AI_NUMERICHOST is set. localhost is not a valid IP address and so getaddrinfo(3) has to fail. Found by anton in pfctl & ipsecctl regress. OK anton --- lib/libc/asr/getaddrinfo_async.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/lib/libc/asr/getaddrinfo_async.c b/lib/libc/asr/getaddrinfo_async.c index d5a9561faf2..a1282e711cd 100644 --- a/lib/libc/asr/getaddrinfo_async.c +++ b/lib/libc/asr/getaddrinfo_async.c @@ -1,4 +1,4 @@ -/* $OpenBSD: getaddrinfo_async.c,v 1.60 2023/11/20 12:15:16 florian Exp $ */ +/* $OpenBSD: getaddrinfo_async.c,v 1.61 2023/11/21 15:26:56 florian Exp $ */ /* * Copyright (c) 2012 Eric Faurot * @@ -115,7 +115,7 @@ getaddrinfo_async_run(struct asr_query *as, struct asr_result *ar) char fqdn[MAXDNAME]; const char *str; struct addrinfo *ai; - int i, family, r, is_localhost; + int i, family, r, is_localhost = 0; FILE *f; union { struct sockaddr sa; @@ -228,7 +228,8 @@ getaddrinfo_async_run(struct asr_query *as, struct asr_result *ar) ar->ar_gai_errno = 0; - is_localhost = _asr_is_localhost(as->as.ai.hostname); + if (!(ai->ai_flags & AI_NUMERICHOST)) + is_localhost = _asr_is_localhost(as->as.ai.hostname); /* * If hostname is NULL, "localhost" or falls within the * ".localhost." domain, use local address. -- 2.20.1