* [PATCH] Fix gethostbyname when using nscd
@ 2005-02-21 21:02 Jakub Jelinek
2005-02-21 23:55 ` Ulrich Drepper
0 siblings, 1 reply; 2+ messages in thread
From: Jakub Jelinek @ 2005-02-21 21:02 UTC (permalink / raw)
To: Ulrich Drepper, Roland McGrath; +Cc: Glibc hackers
Hi!
The first hunk is the most important. Fixes a bug where e.g. with overly
long /etc/hosts entries gethostbyname etc. work only when nscd is turned
off but fail when it is running. The problem is that if h_errno is not set
to NETDB_INTERNAL, the non-_r functions don't consider ERANGE as being
because the buffer was too small and don't retry with a larger size.
The rest of the changes is just something I have noticed during the
debugging - there were a few places which grew the buffer sizes linearly,
which is really slow for very big answers. The other places have been
fixed before already to DTRT.
2005-02-21 Jakub Jelinek <jakub@redhat.com>
* nscd/nscd_gethst_r.c (nscd_gethst_r): Set *h_errnop to
NETDB_INTERNAL if buffer is too small.
* nscd/hstcache.c (INCR): Remove.
(addhstbyX): Double buflen in each iteration rather than add INCR.
* nscd/grpcache.c (INCR): Remove.
(addgrbyX): Double buflen in each iteration rather than add INCR.
* nscd/pwdcache.c (INCR): Remove.
(addpwbyX): Double buflen in each iteration rather than add INCR.
--- libc/nscd/nscd_gethst_r.c.jj 2004-11-10 10:30:32.000000000 +0100
+++ libc/nscd/nscd_gethst_r.c 2005-02-21 21:34:28.644218762 +0100
@@ -1,4 +1,4 @@
-/* Copyright (C) 1998-2002, 2003, 2004 Free Software Foundation, Inc.
+/* Copyright (C) 1998-2002, 2003, 2004, 2005 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@cygnus.com>, 1998.
@@ -218,6 +218,7 @@ nscd_gethst_r (const char *key, size_t k
? INADDRSZ : IN6ADDRSZ)))
{
no_room:
+ *h_errnop = NETDB_INTERNAL;
__set_errno (ERANGE);
retval = ERANGE;
goto out_close;
--- libc/nscd/hstcache.c.jj 2005-01-26 18:36:40.000000000 +0100
+++ libc/nscd/hstcache.c 2005-02-21 21:28:50.806168914 +0100
@@ -1,5 +1,5 @@
/* Cache handling for host lookup.
- Copyright (C) 1998-2002, 2003, 2004 Free Software Foundation, Inc.
+ Copyright (C) 1998-2002, 2003, 2004, 2005 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@cygnus.com>, 1998.
@@ -453,11 +453,10 @@ addhstbyX (struct database_dyn *db, int
{
char *old_buffer = buffer;
errno = 0;
-#define INCR 1024
if (__builtin_expect (buflen > 32768, 0))
{
- buflen += INCR;
+ buflen *= 2;
buffer = (char *) realloc (use_malloc ? buffer : NULL, buflen);
if (buffer == NULL)
{
@@ -478,7 +477,7 @@ addhstbyX (struct database_dyn *db, int
else
/* Allocate a new buffer on the stack. If possible combine it
with the previously allocated buffer. */
- buffer = (char *) extend_alloca (buffer, buflen, buflen + INCR);
+ buffer = (char *) extend_alloca (buffer, buflen, 2 * buflen);
}
#if 0
--- libc/nscd/grpcache.c.jj 2005-01-26 18:36:40.000000000 +0100
+++ libc/nscd/grpcache.c 2005-02-21 21:30:49.876047695 +0100
@@ -1,5 +1,5 @@
/* Cache handling for group lookup.
- Copyright (C) 1998-2002, 2003, 2004 Free Software Foundation, Inc.
+ Copyright (C) 1998-2002, 2003, 2004, 2005 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@cygnus.com>, 1998.
@@ -429,11 +429,10 @@ addgrbyX (struct database_dyn *db, int f
{
char *old_buffer = buffer;
errno = 0;
-#define INCR 1024
if (__builtin_expect (buflen > 32768, 0))
{
- buflen += INCR;
+ buflen *= 2;
buffer = (char *) realloc (use_malloc ? buffer : NULL, buflen);
if (buffer == NULL)
{
@@ -454,7 +453,7 @@ addgrbyX (struct database_dyn *db, int f
else
/* Allocate a new buffer on the stack. If possible combine it
with the previously allocated buffer. */
- buffer = (char *) extend_alloca (buffer, buflen, buflen + INCR);
+ buffer = (char *) extend_alloca (buffer, buflen, 2 * buflen);
}
#if 0
--- libc/nscd/pwdcache.c.jj 2005-01-26 18:36:40.000000000 +0100
+++ libc/nscd/pwdcache.c 2005-02-21 21:31:14.872612500 +0100
@@ -1,5 +1,5 @@
/* Cache handling for passwd lookup.
- Copyright (C) 1998-2002, 2003, 2004 Free Software Foundation, Inc.
+ Copyright (C) 1998-2002, 2003, 2004, 2005 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@cygnus.com>, 1998.
@@ -425,11 +425,10 @@ addpwbyX (struct database_dyn *db, int f
{
char *old_buffer = buffer;
errno = 0;
-#define INCR 1024
if (__builtin_expect (buflen > 32768, 0))
{
- buflen += INCR;
+ buflen *= 2;
buffer = (char *) realloc (use_malloc ? buffer : NULL, buflen);
if (buffer == NULL)
{
@@ -450,7 +449,7 @@ addpwbyX (struct database_dyn *db, int f
else
/* Allocate a new buffer on the stack. If possible combine it
with the previously allocated buffer. */
- buffer = (char *) extend_alloca (buffer, buflen, buflen + INCR);
+ buffer = (char *) extend_alloca (buffer, buflen, 2 * buflen);
}
#if 0
Jakub
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH] Fix gethostbyname when using nscd
2005-02-21 21:02 [PATCH] Fix gethostbyname when using nscd Jakub Jelinek
@ 2005-02-21 23:55 ` Ulrich Drepper
0 siblings, 0 replies; 2+ messages in thread
From: Ulrich Drepper @ 2005-02-21 23:55 UTC (permalink / raw)
To: Jakub Jelinek; +Cc: Glibc hackers
[-- Attachment #1: Type: text/plain, Size: 109 bytes --]
Applied.
--
⧠Ulrich Drepper ⧠Red Hat, Inc. ⧠444 Castro St ⧠Mountain View, CA â
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 252 bytes --]
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2005-02-21 23:55 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-02-21 21:02 [PATCH] Fix gethostbyname when using nscd Jakub Jelinek
2005-02-21 23:55 ` Ulrich Drepper
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).