6ca6e8
commit c36e7cca3571b0c92b09409c1df86a142596c210
6ca6e8
Author: Florian Weimer <fweimer@redhat.com>
6ca6e8
Date:   Tue Aug 30 10:02:49 2022 +0200
6ca6e8
6ca6e8
    nss_dns: In gaih_getanswer_slice, skip strange aliases (bug 12154)
6ca6e8
    
6ca6e8
    If the name is not a host name, skip adding it to the result, instead
6ca6e8
    of reporting query failure.  This fixes bug 12154 for getaddrinfo.
6ca6e8
    
6ca6e8
    This commit still keeps the old parsing code, and only adjusts when
6ca6e8
    a host name is copied.
6ca6e8
    
6ca6e8
    Reviewed-by: Siddhesh Poyarekar <siddhesh@sourceware.org>
6ca6e8
    (cherry picked from commit 32b599ac8c21c4c332cc3900a792a1395bca79c7)
6ca6e8
6ca6e8
diff --git a/resolv/nss_dns/dns-host.c b/resolv/nss_dns/dns-host.c
6ca6e8
index 10c21e1e827cde12..1cb3be71f04d98eb 100644
6ca6e8
--- a/resolv/nss_dns/dns-host.c
6ca6e8
+++ b/resolv/nss_dns/dns-host.c
6ca6e8
@@ -971,12 +971,12 @@ gaih_getanswer_slice (const querybuf *answer, int anslen, const char *qname,
6ca6e8
 
6ca6e8
 	  n = -1;
6ca6e8
 	}
6ca6e8
-      if (__glibc_unlikely (n < 0 || __libc_res_hnok (buffer) == 0))
6ca6e8
+      if (__glibc_unlikely (n < 0))
6ca6e8
 	{
6ca6e8
 	  ++had_error;
6ca6e8
 	  continue;
6ca6e8
 	}
6ca6e8
-      if (*firstp && canon == NULL)
6ca6e8
+      if (*firstp && canon == NULL && __libc_res_hnok (buffer))
6ca6e8
 	{
6ca6e8
 	  h_name = buffer;
6ca6e8
 	  buffer += h_namelen;
6ca6e8
@@ -1022,14 +1022,14 @@ gaih_getanswer_slice (const querybuf *answer, int anslen, const char *qname,
6ca6e8
 
6ca6e8
 	  n = __libc_dn_expand (answer->buf, end_of_message, cp,
6ca6e8
 				tbuf, sizeof tbuf);
6ca6e8
-	  if (__glibc_unlikely (n < 0 || __libc_res_hnok (tbuf) == 0))
6ca6e8
+	  if (__glibc_unlikely (n < 0))
6ca6e8
 	    {
6ca6e8
 	      ++had_error;
6ca6e8
 	      continue;
6ca6e8
 	    }
6ca6e8
 	  cp += n;
6ca6e8
 
6ca6e8
-	  if (*firstp)
6ca6e8
+	  if (*firstp && __libc_res_hnok (tbuf))
6ca6e8
 	    {
6ca6e8
 	      /* Reclaim buffer space.  */
6ca6e8
 	      if (h_name + h_namelen == buffer)