diff mbox series

nss_dns: Adjust ns_name_ntop failure handling in getnetby*

Message ID 20190308204612.5537780DD6B5@oldenburg2.str.redhat.com
State New
Headers show
Series nss_dns: Adjust ns_name_ntop failure handling in getnetby* | expand

Commit Message

Florian Weimer March 8, 2019, 8:46 p.m. UTC
If the function fails, the output buffer is not large enough.  The
function does not fail for any other reason.

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

	* resolv/nss_dns/dns-network.c (getanswer_r): On ns_name_ntop
	failure, the buffer is always too small.
diff mbox series

Patch

diff --git a/resolv/nss_dns/dns-network.c b/resolv/nss_dns/dns-network.c
index 68266d57c9..9b75ac8233 100644
--- a/resolv/nss_dns/dns-network.c
+++ b/resolv/nss_dns/dns-network.c
@@ -324,19 +324,14 @@  getanswer_r (const querybuf *answer, int anslen, struct netent *result,
     {
       int n = __ns_name_unpack (answer->buf, end_of_message, cp,
 				packtmp, sizeof packtmp);
-      if (n != -1 && __ns_name_ntop (packtmp, bp, linebuflen) == -1)
-	{
-	  if (errno == EMSGSIZE)
-	    goto too_small;
-
-	  n = -1;
-	}
-
-      if (n > 0 && bp[0] == '.')
-	bp[0] = '\0';
-
       if (n < 0)
 	goto bad_message;
+      if (__ns_name_ntop (packtmp, bp, linebuflen) < 0)
+	goto too_small;
+
+      if (bp[0] == '.')
+	bp[0] = '\0';
+
       cp += n;
 
       if (end_of_message - cp < 10)
@@ -355,16 +350,11 @@  getanswer_r (const querybuf *answer, int anslen, struct netent *result,
 	{
 	  n = __ns_name_unpack (answer->buf, end_of_message, cp,
 				packtmp, sizeof packtmp);
-	  if (n != -1 && __ns_name_ntop (packtmp, bp, linebuflen) == -1)
-	    {
-	      if (errno == EMSGSIZE)
-		goto too_small;
-
-	      n = -1;
-	    }
-
 	  if (n < 0)
 	    goto bad_message;
+	  if (__ns_name_ntop (packtmp, bp, linebuflen) < 0)
+	    goto too_small;
+
 	  cp += rdatalen;
          if (alias_pointer + 2 < &net_data->aliases[MAX_NR_ALIASES])
            {