olga / rpms / glibc

Forked from rpms/glibc 5 years ago
Clone

Blame SOURCES/glibc-fedora-gai-canonical.patch

00db10
Upstream commit, fixing [BZ #15218]:
00db10
00db10
commit b957ced8890a4438c8efe2c15e5abf4e327f25cf
00db10
Author: Andreas Schwab <schwab@suse.de>
00db10
Date:   Tue Oct 15 10:21:13 2013 +0200
00db10
00db10
    Don't use gethostbyaddr to determine canonical name
00db10
00db10
00db10
--- glibc-2.17-c758a686/sysdeps/posix/getaddrinfo.c
00db10
+++ glibc-2.17-c758a686/sysdeps/posix/getaddrinfo.c
00db10
@@ -565,8 +565,8 @@ gaih_inet (const char *name, const struct gaih_service *service,
00db10
 
00db10
 	  /* If we do not have to look for IPv6 addresses, use
00db10
 	     the simple, old functions, which do not support
00db10
-	     IPv6 scope ids. */
00db10
-	  if (req->ai_family == AF_INET)
00db10
+	     IPv6 scope ids, nor retrieving the canonical name.  */
00db10
+	  if (req->ai_family == AF_INET && (req->ai_flags & AI_CANONNAME) == 0)
00db10
 	    {
00db10
 	      /* Allocate additional room for struct host_data.  */
00db10
 	      size_t tmpbuflen = (512 + MAX_NR_ALIASES * sizeof(char*)
00db10
@@ -1107,70 +1107,10 @@ gaih_inet (const char *name, const struct gaih_service *service,
00db10
 	/* Only the first entry gets the canonical name.  */
00db10
 	if (at2 == at && (req->ai_flags & AI_CANONNAME) != 0)
00db10
 	  {
00db10
-	    char *tmpbuf2 = NULL;
00db10
-	    bool malloc_tmpbuf2 = false;
00db10
-
00db10
 	    if (canon == NULL)
00db10
-	      {
00db10
-		struct hostent *h = NULL;
00db10
-		int herrno;
00db10
-		struct hostent th;
00db10
-		/* Add room for struct host_data.  */
00db10
-		size_t tmpbuf2len = (512 + (MAX_NR_ALIASES+MAX_NR_ADDRS+1)
00db10
-				     * sizeof(char*) + 16 * sizeof(char));
00db10
-
00db10
-		do
00db10
-		  {
00db10
-		    if (__libc_use_alloca (alloca_used + 2 * tmpbuf2len))
00db10
-		      tmpbuf2 = extend_alloca_account (tmpbuf2, tmpbuf2len,
00db10
-						       tmpbuf2len * 2,
00db10
-						       alloca_used);
00db10
-		    else
00db10
-		      {
00db10
-			char *newp = realloc (malloc_tmpbuf2 ? tmpbuf2 : NULL,
00db10
-					      2 * tmpbuf2len);
00db10
-			if (newp == NULL)
00db10
-			  {
00db10
-			    if (malloc_tmpbuf2)
00db10
-			      free (tmpbuf2);
00db10
-			    result = -EAI_MEMORY;
00db10
-			    goto free_and_return;
00db10
-			  }
00db10
-
00db10
-			tmpbuf2 = newp;
00db10
-			tmpbuf2len = 2 * tmpbuf2len;
00db10
-			malloc_tmpbuf2 = true;
00db10
-		      }
00db10
-
00db10
-		    rc = __gethostbyaddr_r (at2->addr,
00db10
-					    ((at2->family == AF_INET6)
00db10
-					     ? sizeof (struct in6_addr)
00db10
-					     : sizeof (struct in_addr)),
00db10
-					    at2->family, &th, tmpbuf2,
00db10
-					    tmpbuf2len, &h, &herrno);
00db10
-		  }
00db10
-		while (rc == ERANGE && herrno == NETDB_INTERNAL);
00db10
-
00db10
-		if (rc != 0 && herrno == NETDB_INTERNAL)
00db10
-		  {
00db10
-		    if (malloc_tmpbuf2)
00db10
-		      free (tmpbuf2);
00db10
-
00db10
-		    __set_h_errno (herrno);
00db10
-		    result = -EAI_SYSTEM;
00db10
-		    goto free_and_return;
00db10
-		  }
00db10
-
00db10
-		if (h != NULL)
00db10
-		  canon = h->h_name;
00db10
-		else
00db10
-		  {
00db10
-		    assert (orig_name != NULL);
00db10
-		    /* If the canonical name cannot be determined, use
00db10
-		       the passed in string.  */
00db10
-		    canon = orig_name;
00db10
-		  }
00db10
-	      }
00db10
+	      /* If the canonical name cannot be determined, use
00db10
+		 the passed in string.  */
00db10
+	      canon = orig_name;
00db10
 
00db10
 #ifdef HAVE_LIBIDN
00db10
 	    if (req->ai_flags & AI_CANONIDN)
00db10
@@ -1185,9 +1125,6 @@ gaih_inet (const char *name, const struct gaih_service *service,
00db10
 		int rc = __idna_to_unicode_lzlz (canon, &out, idn_flags);
00db10
 		if (rc != IDNA_SUCCESS)
00db10
 		  {
00db10
-		    if (malloc_tmpbuf2)
00db10
-		      free (tmpbuf2);
00db10
-
00db10
 		    if (rc == IDNA_MALLOC_ERROR)
00db10
 		      result = -EAI_MEMORY;
00db10
 		    else if (rc == IDNA_DLOPEN_ERROR)
00db10
@@ -1217,17 +1154,11 @@ gaih_inet (const char *name, const struct gaih_service *service,
00db10
 		    canon = strdup (canon);
00db10
 		    if (canon == NULL)
00db10
 		      {
00db10
-			if (malloc_tmpbuf2)
00db10
-			  free (tmpbuf2);
00db10
-
00db10
 			result = -EAI_MEMORY;
00db10
 			goto free_and_return;
00db10
 		      }
00db10
 		  }
00db10
 	      }
00db10
-
00db10
-	    if (malloc_tmpbuf2)
00db10
-	      free (tmpbuf2);
00db10
 	  }
00db10
 
00db10
 	family = at2->family;