From schwab@redhat.com Fri Jun 10 09:25:00 2011 From: schwab@redhat.com (Andreas Schwab) Date: Fri, 10 Jun 2011 09:25:00 -0000 Subject: [PATCH] Fix memory leak in getaddrinfo Message-ID: 2011-06-10 Andreas Schwab * sysdeps/posix/getaddrinfo.c (gaih_inet): Fix logic allocating tmpbuf. --- sysdeps/posix/getaddrinfo.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/sysdeps/posix/getaddrinfo.c b/sysdeps/posix/getaddrinfo.c index 1e017b2..469abe2 100644 --- a/sysdeps/posix/getaddrinfo.c +++ b/sysdeps/posix/getaddrinfo.c @@ -821,7 +821,7 @@ gaih_inet (const char *name, const struct gaih_service *service, size_t tmpbuflen = 1024; malloc_tmpbuf = !__libc_use_alloca (alloca_used + tmpbuflen); assert (tmpbuf == NULL); - if (malloc_tmpbuf) + if (!malloc_tmpbuf) tmpbuf = alloca_account (tmpbuflen, alloca_used); else { -- 1.7.4.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." From drepper@gmail.com Thu Jun 16 01:31:00 2011 From: drepper@gmail.com (Ulrich Drepper) Date: Thu, 16 Jun 2011 01:31:00 -0000 Subject: nss_db is back Message-ID: I've added nss_db back. The current code is abysmal, based on terrible old code, really slow at startup etc. The new code is pretty much a rewrite which doesn't need Berkeley db. Therefore no reason to not carry it in libc itself. People will have to obsolete the nss_db package. The databases have to be re-generated, the new format is obviously not compatible. From schwab@redhat.com Thu Jun 16 14:21:00 2011 From: schwab@redhat.com (Andreas Schwab) Date: Thu, 16 Jun 2011 14:21:00 -0000 Subject: [PATCH] Filter results from gethostbyname4_r according to request flags Message-ID: 2011-06-16 Andreas Schwab [BZ #12885] * sysdeps/posix/getaddrinfo.c (gaih_inet): Filter results from gethostbyname4_r according to request flags. --- sysdeps/posix/getaddrinfo.c | 24 +++++++++++++++++++++++- 1 files changed, 23 insertions(+), 1 deletions(-) diff --git a/sysdeps/posix/getaddrinfo.c b/sysdeps/posix/getaddrinfo.c index 469abe2..1db1e26 100644 --- a/sysdeps/posix/getaddrinfo.c +++ b/sysdeps/posix/getaddrinfo.c @@ -889,7 +889,29 @@ gaih_inet (const char *name, const struct gaih_service *service, canon = (*pat)->name; while (*pat != NULL) - pat = &((*pat)->next); + { + if ((*pat)->family == AF_INET + && req->ai_family == AF_INET6 + && (req->ai_flags & AI_V4MAPPED) != 0) + { + uint32_t *pataddr = (*pat)->addr; + (*pat)->family = AF_INET6; + pataddr[3] = pataddr[0]; + pataddr[2] = htonl (0xffff); + pataddr[1] = 0; + pataddr[0] = 0; + pat = &(*pat)->next; + } + else if ((req->ai_family == AF_UNSPEC + || (*pat)->family == req->ai_family)) + { + if ((*pat)->family == AF_INET6) + got_ipv6 = true; + pat = &(*pat)->next; + } + else + *pat = (*pat)->next; + } } } else -- 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." From schwab@redhat.com Tue Jun 21 15:23:00 2011 From: schwab@redhat.com (Andreas Schwab) Date: Tue, 21 Jun 2011 15:23:00 -0000 Subject: [PATCH] Filter results from gethostbyname4_r according to request flags In-Reply-To: (Andreas Schwab's message of "Thu, 16 Jun 2011 16:21:26 +0200") References: Message-ID: 2011-06-21 Andreas Schwab [BZ #12885] * sysdeps/posix/getaddrinfo.c (gaih_inet): Filter results from gethostbyname4_r according to request flags. --- sysdeps/posix/getaddrinfo.c | 38 +++++++++++++++++++++++++++++++++++--- 1 files changed, 35 insertions(+), 3 deletions(-) diff --git a/sysdeps/posix/getaddrinfo.c b/sysdeps/posix/getaddrinfo.c index 469abe2..7acc73d 100644 --- a/sysdeps/posix/getaddrinfo.c +++ b/sysdeps/posix/getaddrinfo.c @@ -881,16 +881,48 @@ gaih_inet (const char *name, const struct gaih_service *service, } } - no_inet6_data = no_data; - if (status == NSS_STATUS_SUCCESS) { if ((req->ai_flags & AI_CANONNAME) != 0 && canon == NULL) canon = (*pat)->name; while (*pat != NULL) - pat = &((*pat)->next); + { + if ((*pat)->family == AF_INET + && req->ai_family == AF_INET6 + && (req->ai_flags & AI_V4MAPPED) != 0) + { + uint32_t *pataddr = (*pat)->addr; + (*pat)->family = AF_INET6; + pataddr[3] = pataddr[0]; + pataddr[2] = htonl (0xffff); + pataddr[1] = 0; + pataddr[0] = 0; + pat = &(*pat)->next; + } + else if ((req->ai_family == AF_UNSPEC + || (*pat)->family == req->ai_family)) + { + if ((*pat)->family == AF_INET6) + got_ipv6 = true; + pat = &(*pat)->next; + } + else if (*pat == at) + { + if ((*pat)->next != NULL) + memcpy (*pat, (*pat)->next, sizeof (**pat)); + else + { + no_data = 1; + break; + } + } + else + *pat = (*pat)->next; + } } + + no_inet6_data = no_data; } else { -- 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." From drepper@gmail.com Tue Jun 21 21:06:00 2011 From: drepper@gmail.com (Ulrich Drepper) Date: Tue, 21 Jun 2011 21:06:00 -0000 Subject: [PATCH] Filter results from gethostbyname4_r according to request flags In-Reply-To: References: Message-ID: On Tue, Jun 21, 2011 at 11:23, Andreas Schwab wrote: > 2011-06-21 ?Andreas Schwab ? > > ? ? ? ?[BZ #12885] > ? ? ? ?* sysdeps/posix/getaddrinfo.c (gaih_inet): Filter results from > ? ? ? ?gethostbyname4_r according to request flags. This patch isn't correct. We need to ignore the IPv4 entries, keep track of whether we found any data. And there is no reason to copy anything. I think the patch I applied is correct. Give it a try. From schwab@redhat.com Wed Jun 22 12:58:00 2011 From: schwab@redhat.com (Andreas Schwab) Date: Wed, 22 Jun 2011 12:58:00 -0000 Subject: [PATCH] Filter results from gethostbyname4_r according to request flags In-Reply-To: (Ulrich Drepper's message of "Tue, 21 Jun 2011 17:05:34 -0400") References: Message-ID: At last my patch was tested. 2011-06-22 Andreas Schwab * sysdeps/posix/getaddrinfo.c (gaih_inet): Fix last change. --- sysdeps/posix/getaddrinfo.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/sysdeps/posix/getaddrinfo.c b/sysdeps/posix/getaddrinfo.c index 396f120..e6df220 100644 --- a/sysdeps/posix/getaddrinfo.c +++ b/sysdeps/posix/getaddrinfo.c @@ -894,7 +894,7 @@ gaih_inet (const char *name, const struct gaih_service *service, pat = &((*pat)->next); no_data = 0; } - else if ((*pat)->family == AF_UNSPEC + else if (req->ai_family == AF_UNSPEC || (*pat)->family == req->ai_family) { pat = &((*pat)->next); -- 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." From schwab@redhat.com Wed Jun 22 13:12:00 2011 From: schwab@redhat.com (Andreas Schwab) Date: Wed, 22 Jun 2011 13:12:00 -0000 Subject: [PATCH] Don't use gethostbyaddr to determine canonical name Message-ID: 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." From drepper@gmail.com Wed Jun 22 18:41:00 2011 From: drepper@gmail.com (Ulrich Drepper) Date: Wed, 22 Jun 2011 18:41:00 -0000 Subject: [PATCH] Don't use gethostbyaddr to determine canonical name In-Reply-To: References: Message-ID: On Wed, Jun 22, 2011 at 09:12, Andreas Schwab wrote: > 2011-06-22 ?Andreas Schwab ? > > ? ? ? ?* 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. From schwab@redhat.com Fri Jun 24 07:50:00 2011 From: schwab@redhat.com (Andreas Schwab) Date: Fri, 24 Jun 2011 07:50:00 -0000 Subject: [PATCH] Don't use gethostbyaddr to determine canonical name In-Reply-To: (Ulrich Drepper's message of "Wed, 22 Jun 2011 14:40:59 -0400") References: Message-ID: $ 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." From schwab@redhat.com Mon Jun 27 10:53:00 2011 From: schwab@redhat.com (Andreas Schwab) Date: Mon, 27 Jun 2011 10:53:00 -0000 Subject: [PATCH] Fix crash in GB18030 encoder Message-ID: 2011-06-27 Andreas Schwab * iconvdata/gb18030.c (BODY for TO_LOOP): Fix encoding of non-BMP two-byte characters. --- iconvdata/gb18030.c | 12 ++++++------ 1 files changed, 6 insertions(+), 6 deletions(-) diff --git a/iconvdata/gb18030.c b/iconvdata/gb18030.c index f2b23e6..a06b75d 100644 --- a/iconvdata/gb18030.c +++ b/iconvdata/gb18030.c @@ -18233,17 +18233,17 @@ static const unsigned char __ucs_to_gb18030_tab2[][2] = len = 0; \ } \ else if (ch == 0x20087) \ - idx = 0xfe51; \ + cp = (const unsigned char *) "\xfe\x51"; \ else if (ch == 0x20089) \ - idx = 0xfe52; \ + cp = (const unsigned char *) "\xfe\x52"; \ else if (ch == 0x200CC) \ - idx = 0xfe53; \ + cp = (const unsigned char *) "\xfe\x53"; \ else if (ch == 0x215d7) \ - idx = 0xfe6c; \ + cp = (const unsigned char *) "\xfe\x6c"; \ else if (ch == 0x2298F) \ - idx = 0xfe76; \ + cp = (const unsigned char *) "\xfe\x76"; \ else if (ch == 0x241FE) \ - idx = 0xfe91; \ + cp = (const unsigned char *) "\xfe\x91"; \ else \ len = 0; \ \ -- 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." From schwab@redhat.com Thu Jun 30 09:55:00 2011 From: schwab@redhat.com (Andreas Schwab) Date: Thu, 30 Jun 2011 09:55:00 -0000 Subject: [PATCH] Make sure RES_USE_INET6 is always restored Message-ID: 2011-06-30 Andreas Schwab * sysdeps/posix/getaddrinfo.c (gaih_inet): Make sure RES_USE_INET6 is always restored. --- sysdeps/posix/getaddrinfo.c | 4 ++++ 1 files changed, 4 insertions(+), 0 deletions(-) diff --git a/sysdeps/posix/getaddrinfo.c b/sysdeps/posix/getaddrinfo.c index 2b7de7e..3d6506a 100644 --- a/sysdeps/posix/getaddrinfo.c +++ b/sysdeps/posix/getaddrinfo.c @@ -818,6 +818,7 @@ gaih_inet (const char *name, const struct gaih_service *service, tmpbuf = malloc (tmpbuflen); if (tmpbuf == NULL) { + _res.options |= old_res_options & RES_USE_INET6; result = -EAI_MEMORY; goto free_and_return; } @@ -862,6 +863,7 @@ gaih_inet (const char *name, const struct gaih_service *service, 2 * tmpbuflen); if (newp == NULL) { + _res.options |= old_res_options & RES_USE_INET6; result = -EAI_MEMORY; goto free_and_return; } @@ -981,6 +983,8 @@ gaih_inet (const char *name, const struct gaih_service *service, canonbuf = malloc (max_fqdn_len); if (canonbuf == NULL) { + _res.options + |= old_res_options & RES_USE_INET6; result = -EAI_MEMORY; goto free_and_return; } -- 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."