[04/30] nss_dns: Do not use deprecated packet parsing functions

Message ID 8eab562b79d8cfc647668a5a669baec4f303ba93.1625755445.git.fweimer@redhat.com
State Committed
Commit 2ff32dd4926c7ec3bb6c09b58a12a8e828a4cc58
Headers
Series nss_dns move into libc |

Checks

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

Commit Message

Florian Weimer July 8, 2021, 3 p.m. UTC
  ---
 resolv/nss_dns/dns-canon.c | 13 ++++++++-----
 resolv/nss_dns/dns-host.c  | 28 ++++++++++++----------------
 2 files changed, 20 insertions(+), 21 deletions(-)
  

Comments

Carlos O'Donell July 15, 2021, 5 a.m. UTC | #1
On 7/8/21 11:00 AM, Florian Weimer via Libc-alpha wrote:

OK for glibc 2.34.

Tested without regression on x86_64 and i686.

Reviewed-by: Carlos O'Donell <carlos@redhat.com>
Tested-by: Carlos O'Donell <carlos@redhat.com>

> ---
>  resolv/nss_dns/dns-canon.c | 13 ++++++++-----
>  resolv/nss_dns/dns-host.c  | 28 ++++++++++++----------------
>  2 files changed, 20 insertions(+), 21 deletions(-)
> 
> diff --git a/resolv/nss_dns/dns-canon.c b/resolv/nss_dns/dns-canon.c
> index cb321a0650..1cdc9a86c9 100644
> --- a/resolv/nss_dns/dns-canon.c
> +++ b/resolv/nss_dns/dns-canon.c
> @@ -150,15 +150,18 @@ _nss_dns_getcanonname_r (const char *name, char *buffer, size_t buflen,
>  	      if (type != ns_t_cname)
>  		goto unavail;
>  
> -	      if (__ns_get16 (ptr) != ns_c_in)
> +	      uint16_t rrclass;
> +	      NS_GET16 (rrclass, ptr);
> +	      if (rrclass != ns_c_in)

OK. This advances by NS_INT16SZ (which previously did not).

>  		goto unavail;
>  
> -	      /* Also skip over class and TTL.  */
> -	      ptr += sizeof (uint16_t) + sizeof (uint32_t);
> +	      /* Skip over TTL.  */
> +	      ptr += sizeof (uint32_t);

OK. This fixes the advance.

>  
>  	      /* Skip over RDATA length and RDATA itself.  */
> -	      uint16_t rdatalen = __ns_get16 (ptr);
> -	      ptr += sizeof (uint16_t);
> +	      uint16_t rdatalen;
> +	      NS_GET16 (rdatalen, ptr);

OK. No ptr += because NS_GET16 advances by NS_INT16SZ.

> +
>  	      /* Not enough room for RDATA.  */
>  	      if (endptr - ptr < rdatalen)
>  		goto unavail;
> diff --git a/resolv/nss_dns/dns-host.c b/resolv/nss_dns/dns-host.c
> index 47e851db55..d6a69a602a 100644
> --- a/resolv/nss_dns/dns-host.c
> +++ b/resolv/nss_dns/dns-host.c
> @@ -782,14 +782,11 @@ getanswer_r (struct resolv_context *ctx,
>  	  continue;
>  	}
>  
> -      type = __ns_get16 (cp);
> -      cp += INT16SZ;			/* type */
> -      class = __ns_get16 (cp);
> -      cp += INT16SZ;			/* class */
> -      int32_t ttl = __ns_get32 (cp);
> -      cp += INT32SZ;			/* TTL */
> -      n = __ns_get16 (cp);
> -      cp += INT16SZ;			/* len */
> +      NS_GET16 (type, cp);
> +      NS_GET16 (class, cp);
> +      int32_t ttl;
> +      NS_GET32 (ttl, cp);
> +      NS_GET16 (n, cp);		/* RDATA length.  */

OK.

>  
>        if (end_of_message - cp < n)
>  	{
> @@ -1116,14 +1113,13 @@ gaih_getanswer_slice (const querybuf *answer, int anslen, const char *qname,
>  	  continue;
>  	}
>  
> -      int type = __ns_get16 (cp);
> -      cp += INT16SZ;			/* type */
> -      int class = __ns_get16 (cp);
> -      cp += INT16SZ;			/* class */
> -      int32_t ttl = __ns_get32 (cp);
> -      cp += INT32SZ;			/* TTL */
> -      n = __ns_get16 (cp);
> -      cp += INT16SZ;			/* len */
> +      uint16_t type;
> +      NS_GET16 (type, cp);
> +      uint16_t class;
> +      NS_GET16 (class, cp);
> +      int32_t ttl;
> +      NS_GET32 (ttl, cp);
> +      NS_GET16 (n, cp);		/* RDATA length.  */

OK.

>  
>        if (end_of_message - cp < n)
>  	{
>
  

Patch

diff --git a/resolv/nss_dns/dns-canon.c b/resolv/nss_dns/dns-canon.c
index cb321a0650..1cdc9a86c9 100644
--- a/resolv/nss_dns/dns-canon.c
+++ b/resolv/nss_dns/dns-canon.c
@@ -150,15 +150,18 @@  _nss_dns_getcanonname_r (const char *name, char *buffer, size_t buflen,
 	      if (type != ns_t_cname)
 		goto unavail;
 
-	      if (__ns_get16 (ptr) != ns_c_in)
+	      uint16_t rrclass;
+	      NS_GET16 (rrclass, ptr);
+	      if (rrclass != ns_c_in)
 		goto unavail;
 
-	      /* Also skip over class and TTL.  */
-	      ptr += sizeof (uint16_t) + sizeof (uint32_t);
+	      /* Skip over TTL.  */
+	      ptr += sizeof (uint32_t);
 
 	      /* Skip over RDATA length and RDATA itself.  */
-	      uint16_t rdatalen = __ns_get16 (ptr);
-	      ptr += sizeof (uint16_t);
+	      uint16_t rdatalen;
+	      NS_GET16 (rdatalen, ptr);
+
 	      /* Not enough room for RDATA.  */
 	      if (endptr - ptr < rdatalen)
 		goto unavail;
diff --git a/resolv/nss_dns/dns-host.c b/resolv/nss_dns/dns-host.c
index 47e851db55..d6a69a602a 100644
--- a/resolv/nss_dns/dns-host.c
+++ b/resolv/nss_dns/dns-host.c
@@ -782,14 +782,11 @@  getanswer_r (struct resolv_context *ctx,
 	  continue;
 	}
 
-      type = __ns_get16 (cp);
-      cp += INT16SZ;			/* type */
-      class = __ns_get16 (cp);
-      cp += INT16SZ;			/* class */
-      int32_t ttl = __ns_get32 (cp);
-      cp += INT32SZ;			/* TTL */
-      n = __ns_get16 (cp);
-      cp += INT16SZ;			/* len */
+      NS_GET16 (type, cp);
+      NS_GET16 (class, cp);
+      int32_t ttl;
+      NS_GET32 (ttl, cp);
+      NS_GET16 (n, cp);		/* RDATA length.  */
 
       if (end_of_message - cp < n)
 	{
@@ -1116,14 +1113,13 @@  gaih_getanswer_slice (const querybuf *answer, int anslen, const char *qname,
 	  continue;
 	}
 
-      int type = __ns_get16 (cp);
-      cp += INT16SZ;			/* type */
-      int class = __ns_get16 (cp);
-      cp += INT16SZ;			/* class */
-      int32_t ttl = __ns_get32 (cp);
-      cp += INT32SZ;			/* TTL */
-      n = __ns_get16 (cp);
-      cp += INT16SZ;			/* len */
+      uint16_t type;
+      NS_GET16 (type, cp);
+      uint16_t class;
+      NS_GET16 (class, cp);
+      int32_t ttl;
+      NS_GET32 (ttl, cp);
+      NS_GET16 (n, cp);		/* RDATA length.  */
 
       if (end_of_message - cp < n)
 	{