about summary refs log tree commit diff
path: root/resolv/nss_dns/dns-network.c
diff options
context:
space:
mode:
Diffstat (limited to 'resolv/nss_dns/dns-network.c')
-rw-r--r--resolv/nss_dns/dns-network.c50
1 files changed, 14 insertions, 36 deletions
diff --git a/resolv/nss_dns/dns-network.c b/resolv/nss_dns/dns-network.c
index 9a366aca65..5956c84382 100644
--- a/resolv/nss_dns/dns-network.c
+++ b/resolv/nss_dns/dns-network.c
@@ -110,8 +110,8 @@ _nss_dns_getnetbyname_r (const char *name, struct netent *result,
 			 int *herrnop)
 {
   /* Return entry for network with NAME.  */
-  querybuf *net_buffer;
-  int anslen, use_malloc = 0;
+  querybuf *net_buffer, *orig_net_buffer;
+  int anslen;
   char *qbuf;
   enum nss_status status;
 
@@ -120,26 +120,15 @@ _nss_dns_getnetbyname_r (const char *name, struct netent *result,
 
   qbuf = strdupa (name);
 
-  if (!__libc_use_alloca (MAXPACKET))
-    {
-      net_buffer = (querybuf *) malloc (sizeof (querybuf));
-      if (net_buffer == NULL)
-	{
-	  *errnop = ENOMEM;
-	  return NSS_STATUS_UNAVAIL;
-	}
-      use_malloc = 1;
-    }
-  else
-    net_buffer = (querybuf *) alloca (sizeof (querybuf));
+  net_buffer = orig_net_buffer = (querybuf *) alloca (1024);
 
-  anslen = res_nsearch (&_res, qbuf, C_IN, T_PTR, net_buffer->buf,
-			sizeof (net_buffer->buf));
+  anslen = __libc_res_nsearch (&_res, qbuf, C_IN, T_PTR, net_buffer->buf,
+			       1024, (u_char **) &net_buffer);
   if (anslen < 0)
     {
       /* Nothing found.  */
       *errnop = errno;
-      if (use_malloc)
+      if (net_buffer != orig_net_buffer)
 	free (net_buffer);
       return (errno == ECONNREFUSED
 	      || errno == EPFNOSUPPORT
@@ -148,7 +137,7 @@ _nss_dns_getnetbyname_r (const char *name, struct netent *result,
     }
 
   status = getanswer_r (net_buffer, anslen, result, buffer, buflen, BYNAME);
-  if (use_malloc)
+  if (net_buffer != orig_net_buffer)
     free (net_buffer);
   return status;
 }
@@ -161,10 +150,10 @@ _nss_dns_getnetbyaddr_r (uint32_t net, int type, struct netent *result,
 {
   /* Return entry for network with NAME.  */
   enum nss_status status;
-  querybuf *net_buffer;
+  querybuf *net_buffer, *orig_net_buffer;
   unsigned int net_bytes[4];
   char qbuf[MAXDNAME];
-  int cnt, anslen, use_malloc = 0;
+  int cnt, anslen;
   u_int32_t net2;
   int olderr = errno;
 
@@ -201,27 +190,16 @@ _nss_dns_getnetbyaddr_r (uint32_t net, int type, struct netent *result,
       break;
     }
 
-  if (!__libc_use_alloca (MAXPACKET))
-    {
-      net_buffer = (querybuf *) malloc (sizeof (querybuf));
-      if (net_buffer == NULL)
-	{
-	  *errnop = ENOMEM;
-	  return NSS_STATUS_UNAVAIL;
-	}
-      use_malloc = 1;
-    }
-  else
-    net_buffer = (querybuf *) alloca (sizeof (querybuf));
+  net_buffer = orig_net_buffer = (querybuf *) alloca (1024);
 
-  anslen = res_nquery (&_res, qbuf, C_IN, T_PTR, net_buffer->buf,
-		       sizeof (net_buffer->buf));
+  anslen = __libc_res_nquery (&_res, qbuf, C_IN, T_PTR, net_buffer->buf,
+			      1024, (u_char **) &net_buffer);
   if (anslen < 0)
     {
       /* Nothing found.  */
       int err = errno;
       __set_errno (olderr);
-      if (use_malloc)
+      if (net_buffer != orig_net_buffer)
 	free (net_buffer);
       return (err == ECONNREFUSED
 	      || err == EPFNOSUPPORT
@@ -230,7 +208,7 @@ _nss_dns_getnetbyaddr_r (uint32_t net, int type, struct netent *result,
     }
 
   status = getanswer_r (net_buffer, anslen, result, buffer, buflen, BYADDR);
-  if (use_malloc)
+  if (net_buffer != orig_net_buffer)
     free (net_buffer);
   if (status == NSS_STATUS_SUCCESS)
     {