about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog6
-rw-r--r--NEWS14
-rw-r--r--sysdeps/posix/getaddrinfo.c89
3 files changed, 24 insertions, 85 deletions
diff --git a/ChangeLog b/ChangeLog
index 99fa756a9b..83e477d05a 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2013-10-17  Andreas Schwab  <schwab@suse.de>
+
+	[BZ #15218]
+	* sysdeps/posix/getaddrinfo.c (gaih_inet): Don't use gethostbyaddr
+	to determine canonical name.
+
 2013-10-17  Ondřej Bílka  <neleai@seznam.cz>
 
 	* sysdeps/ieee754/dbl-64/dbl2mpn.c: Fix formatting.
diff --git a/NEWS b/NEWS
index 1501f94ea3..507d8fb5c4 100644
--- a/NEWS
+++ b/NEWS
@@ -10,13 +10,13 @@ Version 2.19
 * The following bugs are resolved with this release:
 
   156, 431, 832, 13028, 13982, 13985, 14155, 14547, 14699, 14910, 15048,
-  15308, 15362, 15400, 15427, 15522, 15531, 15532, 15608, 15609, 15610,
-  15632, 15640, 15672, 15680, 15681, 15723, 15734, 15735, 15736, 15748,
-  15749, 15754, 15760, 15764, 15797, 15844, 15847, 15849, 15855, 15856,
-  15857, 15859, 15867, 15886, 15887, 15890, 15892, 15893, 15895, 15897,
-  15905, 15909, 15919, 15921, 15923, 15939, 15963, 15966, 15988, 16032,
-  15905, 15909, 15919, 15921, 15923, 15939, 15963, 15966, 15988, 16032,
-  16034, 16036, 16041.
+  15218, 15308, 15362, 15400, 15427, 15522, 15531, 15532, 15608, 15609,
+  15610, 15632, 15640, 15672, 15680, 15681, 15723, 15734, 15735, 15736,
+  15748, 15749, 15754, 15760, 15764, 15797, 15844, 15847, 15849, 15855,
+  15856, 15857, 15859, 15867, 15886, 15887, 15890, 15892, 15893, 15895,
+  15897, 15905, 15909, 15919, 15921, 15923, 15939, 15963, 15966, 15988,
+  16032, 15905, 15909, 15919, 15921, 15923, 15939, 15963, 15966, 15988,
+  16032, 16034, 16036, 16041.
 
 * CVE-2012-4412 The strcoll implementation caches indices and rules for
   large collation sequences to optimize multiple passes.  This cache
diff --git a/sysdeps/posix/getaddrinfo.c b/sysdeps/posix/getaddrinfo.c
index 170ad8c400..0f4b88514f 100644
--- a/sysdeps/posix/getaddrinfo.c
+++ b/sysdeps/posix/getaddrinfo.c
@@ -564,10 +564,11 @@ gaih_inet (const char *name, const struct gaih_service *service,
 	  int no_more;
 	  int old_res_options;
 
-	  /* If we do not have to look for IPv6 addresses, use
-	     the simple, old functions, which do not support
-	     IPv6 scope ids. */
-	  if (req->ai_family == AF_INET)
+	  /* If we do not have to look for IPv6 addresses or the canonical
+	     name, use the simple, old functions, which do not support
+	     IPv6 scope ids, nor retrieving the canonical name.  */
+	  if (req->ai_family == AF_INET
+	      && (req->ai_flags & AI_CANONNAME) == 0)
 	    {
 	      /* Allocate additional room for struct host_data.  */
 	      size_t tmpbuflen = (512 + MAX_NR_ALIASES * sizeof(char*)
@@ -1009,8 +1010,9 @@ gaih_inet (const char *name, const struct gaih_service *service,
 				    canon = s;
 				  else
 				    {
-				      /* Set to name now to avoid using
-					 gethostbyaddr.  */
+				      /* If the canonical name cannot be
+					 determined, use the passed in
+					 string.  */
 				      if (malloc_canonbuf)
 					{
 					  free (canonbuf);
@@ -1125,70 +1127,10 @@ gaih_inet (const char *name, const struct gaih_service *service,
 	/* Only the first entry gets the canonical name.  */
 	if (at2 == at && (req->ai_flags & AI_CANONNAME) != 0)
 	  {
-	    char *tmpbuf2 = NULL;
-	    bool malloc_tmpbuf2 = false;
-
 	    if (canon == NULL)
-	      {
-		struct hostent *h = NULL;
-		int herrno;
-		struct hostent th;
-		/* Add room for struct host_data.  */
-		size_t tmpbuf2len = (512 + (MAX_NR_ALIASES+MAX_NR_ADDRS+1)
-				     * sizeof(char*) + 16 * sizeof(char));
-
-		do
-		  {
-		    if (__libc_use_alloca (alloca_used + 2 * tmpbuf2len))
-		      tmpbuf2 = extend_alloca_account (tmpbuf2, tmpbuf2len,
-						       tmpbuf2len * 2,
-						       alloca_used);
-		    else
-		      {
-			char *newp = realloc (malloc_tmpbuf2 ? tmpbuf2 : NULL,
-					      2 * tmpbuf2len);
-			if (newp == NULL)
-			  {
-			    if (malloc_tmpbuf2)
-			      free (tmpbuf2);
-			    result = -EAI_MEMORY;
-			    goto free_and_return;
-			  }
-
-			tmpbuf2 = newp;
-			tmpbuf2len = 2 * tmpbuf2len;
-			malloc_tmpbuf2 = true;
-		      }
-
-		    rc = __gethostbyaddr_r (at2->addr,
-					    ((at2->family == AF_INET6)
-					     ? sizeof (struct in6_addr)
-					     : sizeof (struct in_addr)),
-					    at2->family, &th, tmpbuf2,
-					    tmpbuf2len, &h, &herrno);
-		  }
-		while (rc == ERANGE && herrno == NETDB_INTERNAL);
-
-		if (rc != 0 && herrno == NETDB_INTERNAL)
-		  {
-		    if (malloc_tmpbuf2)
-		      free (tmpbuf2);
-
-		    __set_h_errno (herrno);
-		    result = -EAI_SYSTEM;
-		    goto free_and_return;
-		  }
-
-		if (h != NULL)
-		  canon = h->h_name;
-		else
-		  {
-		    assert (orig_name != NULL);
-		    /* If the canonical name cannot be determined, use
-		       the passed in string.  */
-		    canon = orig_name;
-		  }
-	      }
+	      /* If the canonical name cannot be determined, use
+		 the passed in string.  */
+	      canon = orig_name;
 
 #ifdef HAVE_LIBIDN
 	    if (req->ai_flags & AI_CANONIDN)
@@ -1203,9 +1145,6 @@ gaih_inet (const char *name, const struct gaih_service *service,
 		int rc = __idna_to_unicode_lzlz (canon, &out, idn_flags);
 		if (rc != IDNA_SUCCESS)
 		  {
-		    if (malloc_tmpbuf2)
-		      free (tmpbuf2);
-
 		    if (rc == IDNA_MALLOC_ERROR)
 		      result = -EAI_MEMORY;
 		    else if (rc == IDNA_DLOPEN_ERROR)
@@ -1235,17 +1174,11 @@ gaih_inet (const char *name, const struct gaih_service *service,
 		    canon = strdup (canon);
 		    if (canon == NULL)
 		      {
-			if (malloc_tmpbuf2)
-			  free (tmpbuf2);
-
 			result = -EAI_MEMORY;
 			goto free_and_return;
 		      }
 		  }
 	      }
-
-	    if (malloc_tmpbuf2)
-	      free (tmpbuf2);
 	  }
 
 	family = at2->family;