This is the mail archive of the libc-hacker@sourceware.org mailing list for the glibc project.
Note that libc-hacker is a closed list. You may look at the archives of this list, but subscription and posting are not open.
Index Nav: | [Date Index] [Subject Index] [Author Index] [Thread Index] | |
---|---|---|
Message Nav: | [Date Prev] [Date Next] | [Thread Prev] [Thread Next] |
Other format: | [Raw text] |
Hi! 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 <jakub@redhat.com> * 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; #endif - if (trail + sizeof (struct hashentry) > datasize) + if (trail + offsetof (struct hashentry, dellist) > datasize) return NULL; trail = atomic_forced_read (trailelem->next); Jakub
Index Nav: | [Date Index] [Subject Index] [Author Index] [Thread Index] | |
---|---|---|
Message Nav: | [Date Prev] [Date Next] | [Thread Prev] [Thread Next] |