about summary refs log tree commit diff
path: root/nscd/nscd_helper.c
diff options
context:
space:
mode:
authorUlrich Drepper <drepper@redhat.com>2009-05-15 21:33:43 -0700
committerUlrich Drepper <drepper@redhat.com>2009-05-15 21:33:43 -0700
commit831a40494d44045c0caaf8085ab1d35c0da23140 (patch)
tree2a5336cdb2207583c2a42bc99ac8e4a8fbf3dbc7 /nscd/nscd_helper.c
parentcfe1fc1013d0e7e4863c974fa0e78891cc0a2ed2 (diff)
downloadglibc-831a40494d44045c0caaf8085ab1d35c0da23140.tar.gz
glibc-831a40494d44045c0caaf8085ab1d35c0da23140.tar.xz
glibc-831a40494d44045c0caaf8085ab1d35c0da23140.zip
Further robustify nscd database lookup.
We can compute an absolute maximum for the number of elements which
can fit into the currently mapped database.  Stop after that many
iterations.
Diffstat (limited to 'nscd/nscd_helper.c')
-rw-r--r--nscd/nscd_helper.c3
1 files changed, 2 insertions, 1 deletions
diff --git a/nscd/nscd_helper.c b/nscd/nscd_helper.c
index db247962b9..80ee3e1dd9 100644
--- a/nscd/nscd_helper.c
+++ b/nscd/nscd_helper.c
@@ -481,6 +481,7 @@ __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);
   int tick = 0;
 
   while (work != ENDREF && work + sizeof (struct hashentry) <= datasize)
@@ -527,7 +528,7 @@ __nscd_cache_search (request_type type, const char *key, size_t keylen,
       work = atomic_forced_read (here->next);
       /* Prevent endless loops.  This should never happen but perhaps
 	 the database got corrupted, accidentally or deliberately.  */
-      if (work == trail)
+      if (work == trail || loop_cnt-- > 0)
 	break;
       if (tick)
 	{