From: Christophe Fergeau Date: Thu, 17 Feb 2011 21:14:56 +0000 (+0100) Subject: add hash table rebalancing in virHashUpdateEntry X-Git-Tag: CVE-2011-1146~149 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=5c5880e047a24342dd12a1471aaf03ce2fd5cc76;p=thirdparty%2Flibvirt.git add hash table rebalancing in virHashUpdateEntry The code in virHashUpdateEntry and virHashAddEntry is really similar. However, the latter rebalances the hash table when one of its buckets contains too many elements while the former does not. Fix this discrepancy. --- diff --git a/src/util/hash.c b/src/util/hash.c index 41df7ae4f3..59f226b944 100644 --- a/src/util/hash.c +++ b/src/util/hash.c @@ -331,7 +331,7 @@ int virHashUpdateEntry(virHashTablePtr table, const char *name, void *userdata, virHashDeallocator f) { - unsigned long key; + unsigned long key, len = 0; virHashEntryPtr entry; virHashEntryPtr insert; char *new_name; @@ -354,6 +354,7 @@ virHashUpdateEntry(virHashTablePtr table, const char *name, insert->payload = userdata; return (0); } + len++; } if (STREQ(insert->name, name)) { if (f) @@ -386,6 +387,10 @@ virHashUpdateEntry(virHashTablePtr table, const char *name, if (insert != NULL) { insert->next = entry; } + + if (len > MAX_HASH_LEN) + virHashGrow(table, MAX_HASH_LEN * table->size); + return (0); }