public inbox for libc-hacker@sourceware.org
 help / color / mirror / Atom feed
From: Jakub Jelinek <jakub@redhat.com>
To: Ulrich Drepper <drepper@redhat.com>, Roland McGrath <roland@redhat.com>
Cc: Glibc hackers <libc-hacker@sources.redhat.com>
Subject: [PATCH] Fix gethostbyname when using nscd
Date: Mon, 21 Feb 2005 21:02:00 -0000	[thread overview]
Message-ID: <20050221210207.GV4777@sunsite.mff.cuni.cz> (raw)

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

             reply	other threads:[~2005-02-21 21:02 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-02-21 21:02 Jakub Jelinek [this message]
2005-02-21 23:55 ` Ulrich Drepper

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20050221210207.GV4777@sunsite.mff.cuni.cz \
    --to=jakub@redhat.com \
    --cc=drepper@redhat.com \
    --cc=libc-hacker@sources.redhat.com \
    --cc=roland@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).