From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 4684 invoked by alias); 22 Jun 2011 13:12:33 -0000 Received: (qmail 4558 invoked by uid 22791); 22 Jun 2011 13:12:33 -0000 X-SWARE-Spam-Status: No, hits=-6.4 required=5.0 tests=AWL,BAYES_00,RCVD_IN_DNSWL_HI,SPF_HELO_PASS,T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Wed, 22 Jun 2011 13:12:14 +0000 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id p5MDCEdY008079 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Wed, 22 Jun 2011 09:12:14 -0400 Received: from hase (ovpn01.gateway.prod.ext.phx2.redhat.com [10.5.9.1]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id p5MDCCma031185 for ; Wed, 22 Jun 2011 09:12:13 -0400 From: Andreas Schwab To: libc-hacker@sourceware.org Subject: [PATCH] Don't use gethostbyaddr to determine canonical name X-Yow: How do you explain Wayne Newton's POWER over millions? It's th' MOUSTACHE... Have you ever noticed th' way it radiates SINCERITY, HONESTY & WARMTH? It's a MOUSTACHE you want to take HOME and introduce to NANCY SINATRA! Date: Wed, 22 Jun 2011 13:12:00 -0000 Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.3 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Mailing-List: contact libc-hacker-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-hacker-owner@sourceware.org X-SW-Source: 2011-06/txt/msg00006.txt.bz2 2011-06-22 Andreas Schwab * 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."