From eb82f939ee90919c7132bb0282f3fe7ba3c33e8e Mon Sep 17 00:00:00 2001 From: Alasdair Kergon Date: Tue, 3 Nov 2009 00:45:35 +0000 Subject: [PATCH] Fix hash lookup segfault when keys compared are different lengths. --- libdm/datastruct/hash.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/libdm/datastruct/hash.c b/libdm/datastruct/hash.c index 9f8eff645..3c3d8a023 100644 --- a/libdm/datastruct/hash.c +++ b/libdm/datastruct/hash.c @@ -143,9 +143,13 @@ static struct dm_hash_node **_find(struct dm_hash_table *t, const char *key, unsigned h = _hash(key, len) & (t->num_slots - 1); struct dm_hash_node **c; - for (c = &t->slots[h]; *c; c = &((*c)->next)) + for (c = &t->slots[h]; *c; c = &((*c)->next)) { + if ((*c)->keylen != len) + continue; + if (!memcmp(key, (*c)->key, len)) break; + } return c; }