]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
Further robustify nscd database lookup.
authorUlrich Drepper <drepper@redhat.com>
Sat, 16 May 2009 04:33:43 +0000 (21:33 -0700)
committerUlrich Drepper <drepper@redhat.com>
Sat, 16 May 2009 04:33:43 +0000 (21:33 -0700)
We can compute an absolute maximum for the number of elements which
can fit into the currently mapped database.  Stop after that many
iterations.

ChangeLog
nscd/nscd-client.h
nscd/nscd.h
nscd/nscd_helper.c

index aa415cbac21438ea0aad0883a46bfce63fd7cb00..bf3dd4936d9e523b695e48b68749f6b3f61b32ab 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+2009-05-15  Ulrich Drepper  <drepper@redhat.com>
+
+       * nscd/nscd.h: Move Definition for BLOCK_ALIGN_LOG, BLOCK_ALIGN, and
+       BLOCK_ALIGN_M1 to ...
+       * nscd/nscd-client.h: ...here.
+       * nscd/nscd_helper.c (__nscd_cache_search): Introduce loop counter.
+       Use it if we absolutely cannot reach any more correct list elements
+       because that many do not fit into the currently mapped database.
+
 2009-05-14  Jakub Jelinek  <jakub@redhat.com>
 
        * nscd/nscd_helper.c: Include stddef.h.
index f66a658d2a8fb402d3f961ae74e96bd208184b3b..81ca3d56b940f209e973d6903cc6b3668dc1a8b4 100644 (file)
 /* Path for the configuration file.  */
 #define _PATH_NSCDCONF  "/etc/nscd.conf"
 
-/* Maximu allowed length for the key.  */
+/* Maximum allowed length for the key.  */
 #define MAXKEYLEN 1024
 
+/* Maximum alignment requirement we will encounter.  */
+#define BLOCK_ALIGN_LOG 3
+#define BLOCK_ALIGN (1 << BLOCK_ALIGN_LOG)
+#define BLOCK_ALIGN_M1 (BLOCK_ALIGN - 1)
+
 
 /* Available services.  */
 typedef enum
index 3279b8543266307e7f1f4c5dbf50a0d0dee2b767..632bf58dc5c70441739e7d992c3afe93d72801ac 100644 (file)
@@ -111,11 +111,6 @@ struct database_dyn
 /* Path used when not using persistent storage.  */
 #define _PATH_NSCD_XYZ_DB_TMP  "/var/run/nscd/dbXXXXXX"
 
-/* Maximum alignment requirement we will encounter.  */
-#define BLOCK_ALIGN_LOG 3
-#define BLOCK_ALIGN (1 << BLOCK_ALIGN_LOG)
-#define BLOCK_ALIGN_M1 (BLOCK_ALIGN - 1)
-
 /* Default value for the maximum size of the database files.  */
 #define DEFAULT_MAX_DB_SIZE    (32 * 1024 * 1024)
 
index db247962b95f77f3fcd562c7ba25f606f6cb1390..80ee3e1dd9769db0423c45705f0100495a4511f0 100644 (file)
@@ -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)
        {