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

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