public inbox for
 help / color / mirror / Atom feed
* [PATCH] Fix nscd_helper.c
@ 2009-05-18  6:48 Jakub Jelinek
  0 siblings, 0 replies; only message in thread
From: Jakub Jelinek @ 2009-05-18  6:48 UTC (permalink / raw)
  To: Ulrich Drepper; +Cc: Glibc hackers


Adding datalen in __nscd_cache_search is IMHO not correct, some databases
contain mixed type of entries (group contains grp and initgr, hosts hst and
ai responses, which have different datalen).  Additionally some databases
share one datahead with up to two hashentries and in __nscd_cache_search
we want a safe upper bound for number of hash entries.

So, IMHO the right computation is one hashentry and half of a datahead,
without any payload (or with minimum of payloads, but that doesn't make
a very big difference).

Additionally, using sizeof (struct hashentry) in nscd client looks wrong
to me.  What if a 64-bit program using nscd client is run against 32-bit
nscd?  The last union in struct hashentry contains a pointer, if
mempool_alloc allocates the hashentry at the very end of memory, the 64-bit
client would consider it to be out of range.

2009-05-18  Jakub Jelinek  <>

	* nscd/nscd_helper.c (__nscd_cache_search): Assume each entry in the
	hash chain needs one hashentry and half of datahead.  Use offseof
	instead of sizeof for struct hashentry.

diff --git a/nscd/nscd_helper.c b/nscd/nscd_helper.c
index c09f008..bddf3d2 100644
--- a/nscd/nscd_helper.c
+++ b/nscd/nscd_helper.c
@@ -481,10 +481,12 @@ __nscd_cache_search (request_type type, const char *key, size_t keylen,
   ref_t trail = mapped->head->array[hash];
   trail = atomic_forced_read (trail);
   ref_t work = trail;
-  size_t loop_cnt = datasize / (offsetof (struct datahead, data) + datalen);
+  size_t loop_cnt = datasize / (offsetof (struct hashentry, dellist)
+				+ offsetof (struct datahead, data) / 2);
   int tick = 0;
-  while (work != ENDREF && work + sizeof (struct hashentry) <= datasize)
+  while (work != ENDREF
+	 && work + offsetof (struct hashentry, dellist) <= datasize)
       struct hashentry *here = (struct hashentry *) (mapped->data + work);
       ref_t here_key, here_packet;
@@ -541,7 +543,7 @@ __nscd_cache_search (request_type type, const char *key, size_t keylen,
 	    return NULL;
-	  if (trail + sizeof (struct hashentry) > datasize)
+	  if (trail + offsetof (struct hashentry, dellist) > datasize)
 	    return NULL;
 	  trail = atomic_forced_read (trailelem->next);


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2009-05-18  6:48 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-05-18  6:48 [PATCH] Fix nscd_helper.c Jakub Jelinek

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).