arrfab / rpms / glibc

Forked from rpms/glibc 4 years ago
Clone

Blame SOURCES/glibc-rh1047983.patch

147e83
commit 5a4c6d53f50b264d60cf6453576ca2810c7890b7
147e83
Author: Siddhesh Poyarekar <siddhesh@redhat.com>
147e83
Date:   Thu Nov 28 17:18:12 2013 +0530
147e83
147e83
    Get canonical name in getaddrinfo from hosts file for AF_INET (fixes 16077)
147e83
    
147e83
    AF_INET lookup in hosts file uses _nss_files_gethostbyname2_r, which
147e83
    is not capable of returning a canonical name if it has found one.
147e83
    This change adds _nss_files_gethostbyname3_r, which wraps around
147e83
    _nss_files_gethostbyname2_r and then returns result.h_name as the
147e83
    canonical name.
147e83
147e83
diff --git glibc-2.17-c758a686/nss/Versions glibc-2.17-c758a686/nss/Versions
147e83
index d13d570..f8ababc 100644
147e83
--- glibc-2.17-c758a686/nss/Versions
147e83
+++ glibc-2.17-c758a686/nss/Versions
147e83
@@ -40,6 +40,7 @@ libnss_files {
147e83
     _nss_files_endhostent;
147e83
     _nss_files_gethostbyaddr_r;
147e83
     _nss_files_gethostbyname2_r;
147e83
+    _nss_files_gethostbyname3_r;
147e83
     _nss_files_gethostbyname4_r;
147e83
     _nss_files_gethostbyname_r;
147e83
     _nss_files_gethostent_r;
147e83
diff --git glibc-2.17-c758a686/nss/nss_files/files-hosts.c glibc-2.17-c758a686/nss/nss_files/files-hosts.c
147e83
index 6db2535..957c9aa 100644
147e83
--- glibc-2.17-c758a686/nss/nss_files/files-hosts.c
147e83
+++ glibc-2.17-c758a686/nss/nss_files/files-hosts.c
147e83
@@ -97,262 +97,12 @@ LINE_PARSER
147e83
    STRING_FIELD (result->h_name, isspace, 1);
147e83
  })
147e83
 
147e83
-
147e83
-
147e83
-#define HOST_DB_LOOKUP(name, keysize, keypattern, break_if_match, proto...) \
147e83
-enum nss_status								      \
147e83
-_nss_files_get##name##_r (proto,					      \
147e83
-			  struct STRUCTURE *result, char *buffer,	      \
147e83
-			  size_t buflen, int *errnop H_ERRNO_PROTO)	      \
147e83
-{									      \
147e83
-  uintptr_t pad = -(uintptr_t) buffer % __alignof__ (struct hostent_data);    \
147e83
-  buffer += pad;							      \
147e83
-  buflen = buflen > pad ? buflen - pad : 0;				      \
147e83
-									      \
147e83
-  __libc_lock_lock (lock);						      \
147e83
-									      \
147e83
-  /* Reset file pointer to beginning or open file.  */			      \
147e83
-  enum nss_status status = internal_setent (keep_stream);		      \
147e83
-									      \
147e83
-  if (status == NSS_STATUS_SUCCESS)					      \
147e83
-    {									      \
147e83
-      /* Tell getent function that we have repositioned the file pointer.  */ \
147e83
-      last_use = getby;							      \
147e83
-									      \
147e83
-      while ((status = internal_getent (result, buffer, buflen, errnop	      \
147e83
-					H_ERRNO_ARG EXTRA_ARGS_VALUE))	      \
147e83
-	     == NSS_STATUS_SUCCESS)					      \
147e83
-	{ break_if_match }						      \
147e83
-									      \
147e83
-      if (status == NSS_STATUS_SUCCESS					      \
147e83
-	  && _res_hconf.flags & HCONF_FLAG_MULTI)			      \
147e83
-	{								      \
147e83
-	  /* We have to get all host entries from the file.  */		      \
147e83
-	  size_t tmp_buflen = MIN (buflen, 4096);			      \
147e83
-	  char tmp_buffer_stack[tmp_buflen]				      \
147e83
-	    __attribute__ ((__aligned__ (__alignof__ (struct hostent_data))));\
147e83
-	  char *tmp_buffer = tmp_buffer_stack;				      \
147e83
-	  struct hostent tmp_result_buf;				      \
147e83
-	  int naddrs = 1;						      \
147e83
-	  int naliases = 0;						      \
147e83
-	  char *bufferend;						      \
147e83
-	  bool tmp_buffer_malloced = false;				      \
147e83
-									      \
147e83
-	  while (result->h_aliases[naliases] != NULL)			      \
147e83
-	    ++naliases;							      \
147e83
-									      \
147e83
-	  bufferend = (char *) &result->h_aliases[naliases + 1];	      \
147e83
-									      \
147e83
-	again:								      \
147e83
-	  while ((status = internal_getent (&tmp_result_buf, tmp_buffer,      \
147e83
-					    tmp_buflen, errnop H_ERRNO_ARG    \
147e83
-					    EXTRA_ARGS_VALUE))		      \
147e83
-		 == NSS_STATUS_SUCCESS)					      \
147e83
-	    {								      \
147e83
-	      int matches = 1;						      \
147e83
-	      struct hostent *old_result = result;			      \
147e83
-	      result = &tmp_result_buf;					      \
147e83
-	      /* The following piece is a bit clumsy but we want to use the   \
147e83
-		 `break_if_match' value.  The optimizer should do its	      \
147e83
-		 job.  */						      \
147e83
-	      do							      \
147e83
-		{							      \
147e83
-		  break_if_match					      \
147e83
-		  result = old_result;					      \
147e83
-		}							      \
147e83
-	      while ((matches = 0));					      \
147e83
-									      \
147e83
-	      if (matches)						      \
147e83
-		{							      \
147e83
-		  /* We could be very clever and try to recycle a few bytes   \
147e83
-		     in the buffer instead of generating new arrays.  But     \
147e83
-		     we are not doing this here since it's more work than     \
147e83
-		     it's worth.  Simply let the user provide a bit bigger    \
147e83
-		     buffer.  */					      \
147e83
-		  char **new_h_addr_list;				      \
147e83
-		  char **new_h_aliases;					      \
147e83
-		  int newaliases = 0;					      \
147e83
-		  size_t newstrlen = 0;					      \
147e83
-		  int cnt;						      \
147e83
-									      \
147e83
-		  /* Count the new aliases and the length of the strings.  */ \
147e83
-		  while (tmp_result_buf.h_aliases[newaliases] != NULL)	      \
147e83
-		    {							      \
147e83
-		      char *cp = tmp_result_buf.h_aliases[newaliases];	      \
147e83
-		      ++newaliases;					      \
147e83
-		      newstrlen += strlen (cp) + 1;			      \
147e83
-		    }							      \
147e83
-		  /* If the real name is different add it also to the	      \
147e83
-		     aliases.  This means that there is a duplication	      \
147e83
-		     in the alias list but this is really the user's	      \
147e83
-		     problem.  */					      \
147e83
-		  if (strcmp (old_result->h_name,			      \
147e83
-			      tmp_result_buf.h_name) != 0)		      \
147e83
-		    {							      \
147e83
-		      ++newaliases;					      \
147e83
-		      newstrlen += strlen (tmp_result_buf.h_name) + 1;	      \
147e83
-		    }							      \
147e83
-									      \
147e83
-		  /* Make sure bufferend is aligned.  */		      \
147e83
-		  assert ((bufferend - (char *) 0) % sizeof (char *) == 0);   \
147e83
-									      \
147e83
-		  /* Now we can check whether the buffer is large enough.     \
147e83
-		     16 is the maximal size of the IP address.  */	      \
147e83
-		  if (bufferend + 16 + (naddrs + 2) * sizeof (char *)	      \
147e83
-		      + roundup (newstrlen, sizeof (char *))		      \
147e83
-		      + (naliases + newaliases + 1) * sizeof (char *)	      \
147e83
-		      >= buffer + buflen)				      \
147e83
-		    {							      \
147e83
-		      *errnop = ERANGE;					      \
147e83
-		      *herrnop = NETDB_INTERNAL;			      \
147e83
-		      status = NSS_STATUS_TRYAGAIN;			      \
147e83
-		      goto out;						      \
147e83
-		    }							      \
147e83
-									      \
147e83
-		  new_h_addr_list =					      \
147e83
-		    (char **) (bufferend				      \
147e83
-			       + roundup (newstrlen, sizeof (char *))	      \
147e83
-			       + 16);					      \
147e83
-		  new_h_aliases =					      \
147e83
-		    (char **) ((char *) new_h_addr_list			      \
147e83
-			       + (naddrs + 2) * sizeof (char *));	      \
147e83
-									      \
147e83
-		  /* Copy the old data in the new arrays.  */		      \
147e83
-		  for (cnt = 0; cnt < naddrs; ++cnt)			      \
147e83
-		    new_h_addr_list[cnt] = old_result->h_addr_list[cnt];      \
147e83
-									      \
147e83
-		  for (cnt = 0; cnt < naliases; ++cnt)			      \
147e83
-		    new_h_aliases[cnt] = old_result->h_aliases[cnt];	      \
147e83
-									      \
147e83
-		  /* Store the new strings.  */				      \
147e83
-		  cnt = 0;						      \
147e83
-		  while (tmp_result_buf.h_aliases[cnt] != NULL)		      \
147e83
-		    {							      \
147e83
-		      new_h_aliases[naliases++] = bufferend;		      \
147e83
-		      bufferend = (__stpcpy (bufferend,			      \
147e83
-					     tmp_result_buf.h_aliases[cnt])   \
147e83
-				   + 1);				      \
147e83
-		      ++cnt;						      \
147e83
-		    }							      \
147e83
-									      \
147e83
-		  if (cnt < newaliases)					      \
147e83
-		    {							      \
147e83
-		      new_h_aliases[naliases++] = bufferend;		      \
147e83
-		      bufferend = __stpcpy (bufferend,			      \
147e83
-					    tmp_result_buf.h_name) + 1;	      \
147e83
-		    }							      \
147e83
-									      \
147e83
-		  /* Final NULL pointer.  */				      \
147e83
-		  new_h_aliases[naliases] = NULL;			      \
147e83
-									      \
147e83
-		  /* Round up the buffer end address.  */		      \
147e83
-		  bufferend += (sizeof (char *)				      \
147e83
-				- ((bufferend - (char *) 0)		      \
147e83
-				   % sizeof (char *))) % sizeof (char *);     \
147e83
-									      \
147e83
-		  /* Now the new address.  */				      \
147e83
-		  new_h_addr_list[naddrs++] =				      \
147e83
-		    memcpy (bufferend, tmp_result_buf.h_addr,		      \
147e83
-			    tmp_result_buf.h_length);			      \
147e83
-									      \
147e83
-		  /* Also here a final NULL pointer.  */		      \
147e83
-		  new_h_addr_list[naddrs] = NULL;			      \
147e83
-									      \
147e83
-		  /* Store the new array pointers.  */			      \
147e83
-		  old_result->h_aliases = new_h_aliases;		      \
147e83
-		  old_result->h_addr_list = new_h_addr_list;		      \
147e83
-									      \
147e83
-		  /* Compute the new buffer end.  */			      \
147e83
-		  bufferend = (char *) &new_h_aliases[naliases + 1];	      \
147e83
-		  assert (bufferend <= buffer + buflen);		      \
147e83
-									      \
147e83
-		  result = old_result;					      \
147e83
-		}							      \
147e83
-	    }								      \
147e83
-									      \
147e83
-	  if (status == NSS_STATUS_TRYAGAIN)				      \
147e83
-	    {								      \
147e83
-	      size_t newsize = 2 * tmp_buflen;				      \
147e83
-	      if (tmp_buffer_malloced)					      \
147e83
-		{							      \
147e83
-		  char *newp = realloc (tmp_buffer, newsize);		      \
147e83
-		  if (newp != NULL)					      \
147e83
-		    {							      \
147e83
-		      assert ((((uintptr_t) newp)			      \
147e83
-			       & (__alignof__ (struct hostent_data) - 1))     \
147e83
-			      == 0);					      \
147e83
-		      tmp_buffer = newp;				      \
147e83
-		      tmp_buflen = newsize;				      \
147e83
-		      goto again;					      \
147e83
-		    }							      \
147e83
-		}							      \
147e83
-	      else if (!__libc_use_alloca (buflen + newsize))		      \
147e83
-		{							      \
147e83
-		  tmp_buffer = malloc (newsize);			      \
147e83
-		  if (tmp_buffer != NULL)				      \
147e83
-		    {							      \
147e83
-		      assert ((((uintptr_t) tmp_buffer)			      \
147e83
-			       & (__alignof__ (struct hostent_data) - 1))     \
147e83
-			      == 0);					      \
147e83
-		      tmp_buffer_malloced = true;			      \
147e83
-		      tmp_buflen = newsize;				      \
147e83
-		      goto again;					      \
147e83
-		    }							      \
147e83
-		}							      \
147e83
-	      else							      \
147e83
-		{							      \
147e83
-		  tmp_buffer						      \
147e83
-		    = extend_alloca (tmp_buffer, tmp_buflen,		      \
147e83
-				     newsize				      \
147e83
-				     + __alignof__ (struct hostent_data));    \
147e83
-		  tmp_buffer = (char *) (((uintptr_t) tmp_buffer	      \
147e83
-					  + __alignof__ (struct hostent_data) \
147e83
-					  - 1)				      \
147e83
-					 & ~(__alignof__ (struct hostent_data)\
147e83
-					     - 1));			      \
147e83
-		  goto again;						      \
147e83
-		}							      \
147e83
-	    }								      \
147e83
-	  else								      \
147e83
-	    status = NSS_STATUS_SUCCESS;				      \
147e83
-	out:								      \
147e83
-	  if (tmp_buffer_malloced)					      \
147e83
-	    free (tmp_buffer);						      \
147e83
-	}								      \
147e83
-									      \
147e83
-									      \
147e83
-      if (! keep_stream)						      \
147e83
-	internal_endent ();						      \
147e83
-    }									      \
147e83
-									      \
147e83
-  __libc_lock_unlock (lock);						      \
147e83
-									      \
147e83
-  return status;							      \
147e83
-}
147e83
-
147e83
-
147e83
 #define EXTRA_ARGS_VALUE \
147e83
   , ((_res.options & RES_USE_INET6) ? AF_INET6 : AF_INET),		      \
147e83
   ((_res.options & RES_USE_INET6) ? AI_V4MAPPED : 0)
147e83
 #include "files-XXX.c"
147e83
-HOST_DB_LOOKUP (hostbyname, ,,
147e83
-		{
147e83
-		  LOOKUP_NAME_CASE (h_name, h_aliases)
147e83
-		}, const char *name)
147e83
 #undef EXTRA_ARGS_VALUE
147e83
 
147e83
-
147e83
-/* XXX Is using _res to determine whether we want to convert IPv4 addresses
147e83
-   to IPv6 addresses really the right thing to do?  */
147e83
-#define EXTRA_ARGS_VALUE \
147e83
-  , af, ((_res.options & RES_USE_INET6) ? AI_V4MAPPED : 0)
147e83
-HOST_DB_LOOKUP (hostbyname2, ,,
147e83
-		{
147e83
-		  LOOKUP_NAME_CASE (h_name, h_aliases)
147e83
-		}, const char *name, int af)
147e83
-#undef EXTRA_ARGS_VALUE
147e83
-
147e83
-
147e83
 /* We only need to consider IPv4 mapped addresses if the input to the
147e83
    gethostbyaddr() function is an IPv6 address.  */
147e83
 #define EXTRA_ARGS_VALUE \
147e83
@@ -365,6 +115,263 @@ DB_LOOKUP (hostbyaddr, ,,,
147e83
 	   }, const void *addr, socklen_t len, int af)
147e83
 #undef EXTRA_ARGS_VALUE
147e83
 
147e83
+enum nss_status
147e83
+_nss_files_gethostbyname3_r (const char *name, int af, struct hostent *result,
147e83
+			     char *buffer, size_t buflen, int *errnop,
147e83
+			     int *herrnop, int32_t *ttlp, char **canonp)
147e83
+{
147e83
+  uintptr_t pad = -(uintptr_t) buffer % __alignof__ (struct hostent_data);
147e83
+  buffer += pad;
147e83
+  buflen = buflen > pad ? buflen - pad : 0;
147e83
+
147e83
+  __libc_lock_lock (lock);
147e83
+
147e83
+  /* Reset file pointer to beginning or open file.  */
147e83
+  enum nss_status status = internal_setent (keep_stream);
147e83
+
147e83
+  if (status == NSS_STATUS_SUCCESS)
147e83
+    {
147e83
+      /* XXX Is using _res to determine whether we want to convert IPv4
147e83
+         addresses to IPv6 addresses really the right thing to do?  */
147e83
+      int flags = ((_res.options & RES_USE_INET6) ? AI_V4MAPPED : 0);
147e83
+
147e83
+      /* Tell getent function that we have repositioned the file pointer.  */
147e83
+      last_use = getby;
147e83
+
147e83
+      while ((status = internal_getent (result, buffer, buflen, errnop,
147e83
+					herrnop, af, flags))
147e83
+	     == NSS_STATUS_SUCCESS)
147e83
+	{
147e83
+	  LOOKUP_NAME_CASE (h_name, h_aliases)
147e83
+	}
147e83
+
147e83
+      if (status == NSS_STATUS_SUCCESS
147e83
+	  && _res_hconf.flags & HCONF_FLAG_MULTI)
147e83
+	{
147e83
+	  /* We have to get all host entries from the file.  */
147e83
+	  size_t tmp_buflen = MIN (buflen, 4096);
147e83
+	  char tmp_buffer_stack[tmp_buflen]
147e83
+	    __attribute__ ((__aligned__ (__alignof__ (struct hostent_data))));
147e83
+	  char *tmp_buffer = tmp_buffer_stack;
147e83
+	  struct hostent tmp_result_buf;
147e83
+	  int naddrs = 1;
147e83
+	  int naliases = 0;
147e83
+	  char *bufferend;
147e83
+	  bool tmp_buffer_malloced = false;
147e83
+
147e83
+	  while (result->h_aliases[naliases] != NULL)
147e83
+	    ++naliases;
147e83
+
147e83
+	  bufferend = (char *) &result->h_aliases[naliases + 1];
147e83
+
147e83
+	again:
147e83
+	  while ((status = internal_getent (&tmp_result_buf, tmp_buffer,
147e83
+					    tmp_buflen, errnop, herrnop, af,
147e83
+					    flags))
147e83
+		 == NSS_STATUS_SUCCESS)
147e83
+	    {
147e83
+	      int matches = 1;
147e83
+	      struct hostent *old_result = result;
147e83
+	      result = &tmp_result_buf;
147e83
+	      /* The following piece is a bit clumsy but we want to use the
147e83
+		 `LOOKUP_NAME_CASE' value.  The optimizer should do its
147e83
+		 job.  */
147e83
+	      do
147e83
+		{
147e83
+		  LOOKUP_NAME_CASE (h_name, h_aliases)
147e83
+		  result = old_result;
147e83
+		}
147e83
+	      while ((matches = 0));
147e83
+
147e83
+	      if (matches)
147e83
+		{
147e83
+		  /* We could be very clever and try to recycle a few bytes
147e83
+		     in the buffer instead of generating new arrays.  But
147e83
+		     we are not doing this here since it's more work than
147e83
+		     it's worth.  Simply let the user provide a bit bigger
147e83
+		     buffer.  */
147e83
+		  char **new_h_addr_list;
147e83
+		  char **new_h_aliases;
147e83
+		  int newaliases = 0;
147e83
+		  size_t newstrlen = 0;
147e83
+		  int cnt;
147e83
+
147e83
+		  /* Count the new aliases and the length of the strings.  */
147e83
+		  while (tmp_result_buf.h_aliases[newaliases] != NULL)
147e83
+		    {
147e83
+		      char *cp = tmp_result_buf.h_aliases[newaliases];
147e83
+		      ++newaliases;
147e83
+		      newstrlen += strlen (cp) + 1;
147e83
+		    }
147e83
+		  /* If the real name is different add it also to the
147e83
+		     aliases.  This means that there is a duplication
147e83
+		     in the alias list but this is really the user's
147e83
+		     problem.  */
147e83
+		  if (strcmp (old_result->h_name,
147e83
+			      tmp_result_buf.h_name) != 0)
147e83
+		    {
147e83
+		      ++newaliases;
147e83
+		      newstrlen += strlen (tmp_result_buf.h_name) + 1;
147e83
+		    }
147e83
+
147e83
+		  /* Make sure bufferend is aligned.  */
147e83
+		  assert ((bufferend - (char *) 0) % sizeof (char *) == 0);
147e83
+
147e83
+		  /* Now we can check whether the buffer is large enough.
147e83
+		     16 is the maximal size of the IP address.  */
147e83
+		  if (bufferend + 16 + (naddrs + 2) * sizeof (char *)
147e83
+		      + roundup (newstrlen, sizeof (char *))
147e83
+		      + (naliases + newaliases + 1) * sizeof (char *)
147e83
+		      >= buffer + buflen)
147e83
+		    {
147e83
+		      *errnop = ERANGE;
147e83
+		      *herrnop = NETDB_INTERNAL;
147e83
+		      status = NSS_STATUS_TRYAGAIN;
147e83
+		      goto out;
147e83
+		    }
147e83
+
147e83
+		  new_h_addr_list =
147e83
+		    (char **) (bufferend
147e83
+			       + roundup (newstrlen, sizeof (char *))
147e83
+			       + 16);
147e83
+		  new_h_aliases =
147e83
+		    (char **) ((char *) new_h_addr_list
147e83
+			       + (naddrs + 2) * sizeof (char *));
147e83
+
147e83
+		  /* Copy the old data in the new arrays.  */
147e83
+		  for (cnt = 0; cnt < naddrs; ++cnt)
147e83
+		    new_h_addr_list[cnt] = old_result->h_addr_list[cnt];
147e83
+
147e83
+		  for (cnt = 0; cnt < naliases; ++cnt)
147e83
+		    new_h_aliases[cnt] = old_result->h_aliases[cnt];
147e83
+
147e83
+		  /* Store the new strings.  */
147e83
+		  cnt = 0;
147e83
+		  while (tmp_result_buf.h_aliases[cnt] != NULL)
147e83
+		    {
147e83
+		      new_h_aliases[naliases++] = bufferend;
147e83
+		      bufferend = (__stpcpy (bufferend,
147e83
+					     tmp_result_buf.h_aliases[cnt])
147e83
+				   + 1);
147e83
+		      ++cnt;
147e83
+		    }
147e83
+
147e83
+		  if (cnt < newaliases)
147e83
+		    {
147e83
+		      new_h_aliases[naliases++] = bufferend;
147e83
+		      bufferend = __stpcpy (bufferend,
147e83
+					    tmp_result_buf.h_name) + 1;
147e83
+		    }
147e83
+
147e83
+		  /* Final NULL pointer.  */
147e83
+		  new_h_aliases[naliases] = NULL;
147e83
+
147e83
+		  /* Round up the buffer end address.  */
147e83
+		  bufferend += (sizeof (char *)
147e83
+				- ((bufferend - (char *) 0)
147e83
+				   % sizeof (char *))) % sizeof (char *);
147e83
+
147e83
+		  /* Now the new address.  */
147e83
+		  new_h_addr_list[naddrs++] =
147e83
+		    memcpy (bufferend, tmp_result_buf.h_addr,
147e83
+			    tmp_result_buf.h_length);
147e83
+
147e83
+		  /* Also here a final NULL pointer.  */
147e83
+		  new_h_addr_list[naddrs] = NULL;
147e83
+
147e83
+		  /* Store the new array pointers.  */
147e83
+		  old_result->h_aliases = new_h_aliases;
147e83
+		  old_result->h_addr_list = new_h_addr_list;
147e83
+
147e83
+		  /* Compute the new buffer end.  */
147e83
+		  bufferend = (char *) &new_h_aliases[naliases + 1];
147e83
+		  assert (bufferend <= buffer + buflen);
147e83
+
147e83
+		  result = old_result;
147e83
+		}
147e83
+	    }
147e83
+
147e83
+	  if (status == NSS_STATUS_TRYAGAIN)
147e83
+	    {
147e83
+	      size_t newsize = 2 * tmp_buflen;
147e83
+	      if (tmp_buffer_malloced)
147e83
+		{
147e83
+		  char *newp = realloc (tmp_buffer, newsize);
147e83
+		  if (newp != NULL)
147e83
+		    {
147e83
+		      assert ((((uintptr_t) newp)
147e83
+			       & (__alignof__ (struct hostent_data) - 1))
147e83
+			      == 0);
147e83
+		      tmp_buffer = newp;
147e83
+		      tmp_buflen = newsize;
147e83
+		      goto again;
147e83
+		    }
147e83
+		}
147e83
+	      else if (!__libc_use_alloca (buflen + newsize))
147e83
+		{
147e83
+		  tmp_buffer = malloc (newsize);
147e83
+		  if (tmp_buffer != NULL)
147e83
+		    {
147e83
+		      assert ((((uintptr_t) tmp_buffer)
147e83
+			       & (__alignof__ (struct hostent_data) - 1))
147e83
+			      == 0);
147e83
+		      tmp_buffer_malloced = true;
147e83
+		      tmp_buflen = newsize;
147e83
+		      goto again;
147e83
+		    }
147e83
+		}
147e83
+	      else
147e83
+		{
147e83
+		  tmp_buffer
147e83
+		    = extend_alloca (tmp_buffer, tmp_buflen,
147e83
+				     newsize
147e83
+				     + __alignof__ (struct hostent_data));
147e83
+		  tmp_buffer = (char *) (((uintptr_t) tmp_buffer
147e83
+					  + __alignof__ (struct hostent_data)
147e83
+					  - 1)
147e83
+					 & ~(__alignof__ (struct hostent_data)
147e83
+					     - 1));
147e83
+		  goto again;
147e83
+		}
147e83
+	    }
147e83
+	  else
147e83
+	    status = NSS_STATUS_SUCCESS;
147e83
+	out:
147e83
+	  if (tmp_buffer_malloced)
147e83
+	    free (tmp_buffer);
147e83
+	}
147e83
+
147e83
+      if (! keep_stream)
147e83
+	internal_endent ();
147e83
+    }
147e83
+
147e83
+  if (canonp && status == NSS_STATUS_SUCCESS)
147e83
+    *canonp = result->h_name;
147e83
+
147e83
+  __libc_lock_unlock (lock);
147e83
+
147e83
+  return status;
147e83
+}
147e83
+
147e83
+enum nss_status
147e83
+_nss_files_gethostbyname_r (const char *name, struct hostent *result,
147e83
+			    char *buffer, size_t buflen, int *errnop,
147e83
+			    int *herrnop)
147e83
+{
147e83
+  int af = ((_res.options & RES_USE_INET6) ? AF_INET6 : AF_INET);
147e83
+
147e83
+  return _nss_files_gethostbyname3_r (name, af, result, buffer, buflen,
147e83
+				      errnop, herrnop, NULL, NULL);
147e83
+}
147e83
+
147e83
+enum nss_status
147e83
+_nss_files_gethostbyname2_r (const char *name, int af, struct hostent *result,
147e83
+			     char *buffer, size_t buflen, int *errnop,
147e83
+			     int *herrnop)
147e83
+{
147e83
+  return _nss_files_gethostbyname3_r (name, af, result, buffer, buflen,
147e83
+				      errnop, herrnop, NULL, NULL);
147e83
+}
147e83
 
147e83
 enum nss_status
147e83
 _nss_files_gethostbyname4_r (const char *name, struct gaih_addrtuple **pat,