Patchwork nss_dns: More consistency in corrupt message handling in getnetby*

login
register
mail settings
Submitter Florian Weimer
Date March 8, 2019, 8:45 p.m.
Message ID <20190308204512.4EC1780DD6B5@oldenburg2.str.redhat.com>
Download mbox | patch
Permalink /patch/31789/
State New
Headers show

Comments

Florian Weimer - March 8, 2019, 8:45 p.m.
If a parse error is encountered, fail with NO_RECOVERY and
NSS_STATUS_UNAVAIL.

2019-03-08  Florian Weimer  <fweimer@redhat.com>

	* resolv/nss_dns/dns-network.c (getanswer_r): Handle unparseable
	messages more consistently.

Patch

diff --git a/resolv/nss_dns/dns-network.c b/resolv/nss_dns/dns-network.c
index 9c0082d270..68266d57c9 100644
--- a/resolv/nss_dns/dns-network.c
+++ b/resolv/nss_dns/dns-network.c
@@ -336,14 +336,11 @@  getanswer_r (const querybuf *answer, int anslen, struct netent *result,
 	bp[0] = '\0';
 
       if (n < 0)
-	break;
+	goto bad_message;
       cp += n;
 
       if (end_of_message - cp < 10)
-	{
-	  __set_h_errno (NO_RECOVERY);
-	  return NSS_STATUS_UNAVAIL;
-	}
+	goto bad_message;
 
       int type, class;
       GETSHORT (type, cp);
@@ -352,10 +349,7 @@  getanswer_r (const querybuf *answer, int anslen, struct netent *result,
       uint16_t rdatalen;
       GETSHORT (rdatalen, cp);
       if (end_of_message - cp < rdatalen)
-	{
-	  __set_h_errno (NO_RECOVERY);
-	  return NSS_STATUS_UNAVAIL;
-	}
+	goto bad_message;
 
       if (class == C_IN && type == T_PTR)
 	{
@@ -370,13 +364,7 @@  getanswer_r (const querybuf *answer, int anslen, struct netent *result,
 	    }
 
 	  if (n < 0)
-	    {
-	      /* XXX What does this mean?  The original form from bind
-		 returns NULL. Incrementing cp has no effect in any case.
-		 What should I return here. ??? */
-	      cp += n;
-	      return NSS_STATUS_UNAVAIL;
-	    }
+	    goto bad_message;
 	  cp += rdatalen;
          if (alias_pointer + 2 < &net_data->aliases[MAX_NR_ALIASES])
            {