Send patches - preferably formatted by git format-patch - to patches at archlinux32 dot org.
summaryrefslogtreecommitdiff
path: root/lib/libalpm/pkghash.c
diff options
context:
space:
mode:
authorAllan McRae <allan@archlinux.org>2011-01-29 11:39:25 +1000
committerAllan McRae <allan@archlinux.org>2011-02-04 09:55:45 +1000
commitd843c86b7b7cbf376716817e7c2c55b1f9360a72 (patch)
tree0f1d6d7501333df041871781c0b24faadc8200e6 /lib/libalpm/pkghash.c
parent021085624ea94a7116c60552e5c153de6cb5f057 (diff)
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 <allan@archlinux.org>
Diffstat (limited to 'lib/libalpm/pkghash.c')
-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);
}