On 08/31/2010 08:11 AM, Eric Blake wrote:
On 08/31/2010 02:10 AM, Jim Meyering wrote:
Eric, I've listed you as an author, so will wait for your ACK.
From 5bcff7b85b7b88fa4809ad874a1203e27abed085 Mon Sep 17 00:00:00 2001
From: Eric Blake<ebl...@redhat.com>
Date: Tue, 31 Aug 2010 10:06:16 +0200
Subject: [PATCH] hash: factor, and guard against misbehaving hasher
function
* lib/hash.c (safe_hasher): New function, to encapsulate the checking
of table->hasher's return value. Also protect against a hash value
so large that adding it to table->bucket would result in a NULL pointer.
(hash_lookup, hash_get_next, hash_find_entry): Use it in place of
open-coded check-and-abort.
ACK from me.
Actually, you missed one function. I'm squashing this in, then pushing.
diff --git i/ChangeLog w/ChangeLog
index ef3adf1..9ed2f79 100644
--- i/ChangeLog
+++ w/ChangeLog
@@ -1,12 +1,12 @@
2010-08-31 Eric Blake <ebl...@redhat.com>
- Jim Meyering <meyer...@redhat.com>
+ and Jim Meyering <meyer...@redhat.com>
hash: factor, and guard against misbehaving hasher function
* lib/hash.c (safe_hasher): New function, to encapsulate the checking
of table->hasher's return value. Also protect against a hash value
so large that adding it to table->bucket would result in a NULL pointer.
- (hash_lookup, hash_get_next, hash_find_entry): Use it in place of
- open-coded check-and-abort.
+ (hash_lookup, hash_get_next, hash_find_entry, transfer_entries):
+ Use it in place of open-coded check-and-abort.
2010-08-30 Bruno Haible <br...@clisp.org>
diff --git i/lib/hash.c w/lib/hash.c
index 30a10b1..a4a2420 100644
--- i/lib/hash.c
+++ w/lib/hash.c
@@ -877,10 +877,7 @@ transfer_entries (Hash_table *dst, Hash_table *src, bool
safe)
for (cursor = bucket->next; cursor; cursor = next)
{
data = cursor->data;
- new_bucket = (dst->bucket + dst->hasher (data, dst->n_buckets));
-
- if (! (new_bucket < dst->bucket_limit))
- abort ();
+ new_bucket = safe_hasher (dst, data);
next = cursor->next;
@@ -907,10 +904,7 @@ transfer_entries (Hash_table *dst, Hash_table *src, bool
safe)
bucket->next = NULL;
if (safe)
continue;
- new_bucket = (dst->bucket + dst->hasher (data, dst->n_buckets));
-
- if (! (new_bucket < dst->bucket_limit))
- abort ();
+ new_bucket = safe_hasher (dst, data);
if (new_bucket->data)
{
--
Eric Blake ebl...@redhat.com +1-801-349-2682
Libvirt virtualization library http://libvirt.org