From: Jakub Jelinek <jakub@redhat.com>
To: Ulrich Drepper <drepper@redhat.com>
Cc: Glibc hackers <libc-hacker@sources.redhat.com>
Subject: [PATCH] Fix nscd_helper.c
Date: Mon, 18 May 2009 06:48:00 -0000 [thread overview]
Message-ID: <20090518070057.GO16681@sunsite.ms.mff.cuni.cz> (raw)
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
reply other threads:[~2009-05-18 6:48 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=20090518070057.GO16681@sunsite.ms.mff.cuni.cz \
--to=jakub@redhat.com \
--cc=drepper@redhat.com \
--cc=libc-hacker@sources.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).