summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/libalpm/pkghash.c12
1 files changed, 12 insertions, 0 deletions
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);
}