arrfab / rpms / glibc

Forked from rpms/glibc 4 years ago
Clone

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

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