[11/13] nss_dns: In gaih_getanswer_slice, skip strange aliases (bug 12154)

Message ID a2475d6fc9cbc351e19556068dbfe90369b0d3f8.1660123636.git.fweimer@redhat.com
State Committed
Commit 32b599ac8c21c4c332cc3900a792a1395bca79c7
Delegated to: Siddhesh Poyarekar
Headers
Series nss_dns: Fix handling of non-host CNAMEs (bug 12154) |

Checks

Context Check Description
dj/TryBot-apply_patch success Patch applied to master at the time it was sent

Commit Message

Florian Weimer Aug. 10, 2022, 9:31 a.m. UTC
  If the name is not a host name, skip adding it to the result, instead
of reporting query failure.  This fixes bug 12154 for getaddrinfo.

This commit still keeps the old parsing code, and only adjusts when
a host name is copied.
---
 resolv/nss_dns/dns-host.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
  

Comments

Siddhesh Poyarekar Aug. 23, 2022, 12:23 p.m. UTC | #1
On 2022-08-10 05:31, Florian Weimer via Libc-alpha wrote:
> If the name is not a host name, skip adding it to the result, instead
> of reporting query failure.  This fixes bug 12154 for getaddrinfo.
> 
> This commit still keeps the old parsing code, and only adjusts when
> a host name is copied.
> ---
>   resolv/nss_dns/dns-host.c | 8 ++++----
>   1 file changed, 4 insertions(+), 4 deletions(-)

LGTM.

Reviewed-by: Siddhesh Poyarekar <siddhesh@sourceware.org>

> 
> diff --git a/resolv/nss_dns/dns-host.c b/resolv/nss_dns/dns-host.c
> index 0e7eef6889..809a269a7c 100644
> --- a/resolv/nss_dns/dns-host.c
> +++ b/resolv/nss_dns/dns-host.c
> @@ -970,12 +970,12 @@ gaih_getanswer_slice (const querybuf *answer, int anslen, const char *qname,
>   
>   	  n = -1;
>   	}
> -      if (__glibc_unlikely (n < 0 || __libc_res_hnok (buffer) == 0))
> +      if (__glibc_unlikely (n < 0))
>   	{
>   	  ++had_error;
>   	  continue;
>   	}
> -      if (*firstp && canon == NULL)
> +      if (*firstp && canon == NULL && __libc_res_hnok (buffer))
>   	{
>   	  h_name = buffer;
>   	  buffer += h_namelen;
> @@ -1021,14 +1021,14 @@ gaih_getanswer_slice (const querybuf *answer, int anslen, const char *qname,
>   
>   	  n = __libc_dn_expand (answer->buf, end_of_message, cp,
>   				tbuf, sizeof tbuf);
> -	  if (__glibc_unlikely (n < 0 || __libc_res_hnok (tbuf) == 0))
> +	  if (__glibc_unlikely (n < 0))
>   	    {
>   	      ++had_error;
>   	      continue;
>   	    }
>   	  cp += n;
>   
> -	  if (*firstp)
> +	  if (*firstp && __libc_res_hnok (tbuf))
>   	    {
>   	      /* Reclaim buffer space.  */
>   	      if (h_name + h_namelen == buffer)
  

Patch

diff --git a/resolv/nss_dns/dns-host.c b/resolv/nss_dns/dns-host.c
index 0e7eef6889..809a269a7c 100644
--- a/resolv/nss_dns/dns-host.c
+++ b/resolv/nss_dns/dns-host.c
@@ -970,12 +970,12 @@  gaih_getanswer_slice (const querybuf *answer, int anslen, const char *qname,
 
 	  n = -1;
 	}
-      if (__glibc_unlikely (n < 0 || __libc_res_hnok (buffer) == 0))
+      if (__glibc_unlikely (n < 0))
 	{
 	  ++had_error;
 	  continue;
 	}
-      if (*firstp && canon == NULL)
+      if (*firstp && canon == NULL && __libc_res_hnok (buffer))
 	{
 	  h_name = buffer;
 	  buffer += h_namelen;
@@ -1021,14 +1021,14 @@  gaih_getanswer_slice (const querybuf *answer, int anslen, const char *qname,
 
 	  n = __libc_dn_expand (answer->buf, end_of_message, cp,
 				tbuf, sizeof tbuf);
-	  if (__glibc_unlikely (n < 0 || __libc_res_hnok (tbuf) == 0))
+	  if (__glibc_unlikely (n < 0))
 	    {
 	      ++had_error;
 	      continue;
 	    }
 	  cp += n;
 
-	  if (*firstp)
+	  if (*firstp && __libc_res_hnok (tbuf))
 	    {
 	      /* Reclaim buffer space.  */
 	      if (h_name + h_namelen == buffer)