From d843c86b7b7cbf376716817e7c2c55b1f9360a72 Mon Sep 17 00:00:00 2001 From: Allan McRae Date: Sat, 29 Jan 2011 11:39:25 +1000 Subject: Error handling for maximum database size Check that the requested size of a pkghash is not beyond the maximum prime. Also check for successful creation of a new hash before rehashing. Signed-off-by: Allan McRae --- lib/libalpm/pkghash.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'lib/libalpm/pkghash.c') diff --git a/lib/libalpm/pkghash.c b/lib/libalpm/pkghash.c index f2497070..0324465f 100644 --- a/lib/libalpm/pkghash.c +++ b/lib/libalpm/pkghash.c @@ -59,6 +59,7 @@ pmpkghash_t *_alpm_pkghash_create(size_t size) hash->list = NULL; hash->entries = 0; + hash->buckets = 0; loopsize = sizeof(prime_list) / sizeof(*prime_list); for(i = 0; i < loopsize; i++) { @@ -68,6 +69,12 @@ pmpkghash_t *_alpm_pkghash_create(size_t size) } } + if(hash->buckets < size) { + _alpm_log(PM_LOG_ERROR, _("database larger than maximum size")); + free(hash); + return(NULL); + } + CALLOC(hash->hash_table, hash->buckets, sizeof(alpm_list_t*), \ free(hash); RET_ERR(PM_ERR_MEMORY, NULL)); @@ -98,6 +105,11 @@ static pmpkghash_t *rehash(pmpkghash_t *oldhash) } newhash = _alpm_pkghash_create(newsize); + if(newhash == NULL) { + /* creation of newhash failed, stick with old one... */ + return(oldhash); + } + for(ptr = oldhash->list; ptr != NULL; ptr = ptr->next) { newhash = _alpm_pkghash_add(newhash, ptr->data); } -- cgit v1.2.3-24-g4f1b