public inbox for libc-hacker@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] Don't use gethostbyaddr to determine canonical name
@ 2011-06-22 13:12 Andreas Schwab
  2011-06-22 18:41 ` Ulrich Drepper
  0 siblings, 1 reply; 5+ messages in thread
From: Andreas Schwab @ 2011-06-22 13:12 UTC (permalink / raw)
  To: libc-hacker

2011-06-22  Andreas Schwab  <schwab@redhat.com>

	* sysdeps/posix/getaddrinfo.c (gaih_inet): Don't use gethostbyaddr
	to determine canonical name.
---
 sysdeps/posix/getaddrinfo.c |   77 +++----------------------------------------
 1 files changed, 5 insertions(+), 72 deletions(-)

diff --git a/sysdeps/posix/getaddrinfo.c b/sysdeps/posix/getaddrinfo.c
index 14e9270..e6df220 100644
--- a/sysdeps/posix/getaddrinfo.c
+++ b/sysdeps/posix/getaddrinfo.c
@@ -562,8 +562,8 @@ gaih_inet (const char *name, const struct gaih_service *service,
 
 	  /* 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)
+	     IPv6 scope ids, nor retrieving the canonical name.  */
+	  if (req->ai_family == AF_INET && (req->ai_flags & AI_CANONNAME) == 0)
 	    {
 	      size_t tmpbuflen = 512;
 	      assert (tmpbuf == NULL);
@@ -1098,68 +1098,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;
-		size_t tmpbuf2len = 512;
-
-		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)
@@ -1174,9 +1116,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)
@@ -1206,17 +1145,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;
-- 
1.7.5.4


-- 
Andreas Schwab, schwab@redhat.com
GPG Key fingerprint = D4E8 DBE3 3813 BB5D FA84  5EC7 45C6 250E 6F00 984E
"And now for something completely different."

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] Don't use gethostbyaddr to determine canonical name
  2011-06-22 13:12 [PATCH] Don't use gethostbyaddr to determine canonical name Andreas Schwab
@ 2011-06-22 18:41 ` Ulrich Drepper
  2011-06-24  7:50   ` Andreas Schwab
  0 siblings, 1 reply; 5+ messages in thread
From: Ulrich Drepper @ 2011-06-22 18:41 UTC (permalink / raw)
  To: Andreas Schwab; +Cc: libc-hacker

On Wed, Jun 22, 2011 at 09:12, Andreas Schwab <schwab@redhat.com> wrote:
> 2011-06-22  Andreas Schwab  <schwab@redhat.com>
>
>        * sysdeps/posix/getaddrinfo.c (gaih_inet): Don't use gethostbyaddr
>        to determine canonical name.

Explain the patch.  As usual there is nothing.  Of course using
gethostbyaddr is not perfect.  This is the last ditch effort.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] Don't use gethostbyaddr to determine canonical name
  2011-06-22 18:41 ` Ulrich Drepper
@ 2011-06-24  7:50   ` Andreas Schwab
  2011-07-04 21:54     ` Ulrich Drepper
  0 siblings, 1 reply; 5+ messages in thread
From: Andreas Schwab @ 2011-06-24  7:50 UTC (permalink / raw)
  To: Ulrich Drepper; +Cc: libc-hacker

$ getent ahosts www.google.de | head -1
2a00:1450:8007::6a STREAM www.l.google.com
$ getent ahostsv4 www.google.de | head -1
74.125.39.106   STREAM fx-in-f106.1e100.net

Andreas.

-- 
Andreas Schwab, schwab@redhat.com
GPG Key fingerprint = D4E8 DBE3 3813 BB5D FA84  5EC7 45C6 250E 6F00 984E
"And now for something completely different."

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] Don't use gethostbyaddr to determine canonical name
  2011-06-24  7:50   ` Andreas Schwab
@ 2011-07-04 21:54     ` Ulrich Drepper
  2011-07-05  8:12       ` Andreas Schwab
  0 siblings, 1 reply; 5+ messages in thread
From: Ulrich Drepper @ 2011-07-04 21:54 UTC (permalink / raw)
  To: Andreas Schwab; +Cc: libc-hacker

On Fri, Jun 24, 2011 at 03:49, Andreas Schwab <schwab@redhat.com> wrote:
> $ getent ahosts www.google.de | head -1
> 2a00:1450:8007::6a STREAM www.l.google.com
> $ getent ahostsv4 www.google.de | head -1
> 74.125.39.106   STREAM fx-in-f106.1e100.net

I cannot reproduce this.  Must have been on IPv6-day!?

What is the exact situation?  The patch isn't correct.  If anything is
wrong then it might be that we need to use the gethostbyname-based
implementation in even fewer situations or the getcanon implementation
has a problem.

The 1e100.net address obviously also belongs to Google.  Therefore I'm
not really sure there is a problem.  They might have directed IPv4 and
IPv6 traffic to completely different machines.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] Don't use gethostbyaddr to determine canonical name
  2011-07-04 21:54     ` Ulrich Drepper
@ 2011-07-05  8:12       ` Andreas Schwab
  0 siblings, 0 replies; 5+ messages in thread
From: Andreas Schwab @ 2011-07-05  8:12 UTC (permalink / raw)
  To: Ulrich Drepper; +Cc: libc-hacker

A PTR isn't a canonical name.  See RFC 1034.

Andreas.

-- 
Andreas Schwab, schwab@redhat.com
GPG Key fingerprint = D4E8 DBE3 3813 BB5D FA84  5EC7 45C6 250E 6F00 984E
"And now for something completely different."

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2011-07-05  8:12 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-06-22 13:12 [PATCH] Don't use gethostbyaddr to determine canonical name Andreas Schwab
2011-06-22 18:41 ` Ulrich Drepper
2011-06-24  7:50   ` Andreas Schwab
2011-07-04 21:54     ` Ulrich Drepper
2011-07-05  8:12       ` Andreas Schwab

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).