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:
authorAndrew Gregory <andrew.gregory.8@gmail.com>2018-01-07 19:30:42 -0500
committerAllan McRae <allan@archlinux.org>2018-01-10 10:52:26 +1000
commit2bda849bf9b39b423175d1ee1d8796b856cc9988 (patch)
tree457191f5eae040c3c37b152fe14dab275ff4c0af /lib/libalpm/pkghash.c
parent59b6fdeee1722a58d1599bcbd1e2c0fc33debc99 (diff)
detect pkghash allocation failure
If rehash ever failed with a full hash it would return the old hash that is already full. get_hash_position would then loop forever because it would never find an empty bucket. Signed-off-by: Andrew Gregory <andrew.gregory.8@gmail.com> Signed-off-by: Allan McRae <allan@archlinux.org>
Diffstat (limited to 'lib/libalpm/pkghash.c')
-rw-r--r--lib/libalpm/pkghash.c23
1 files changed, 14 insertions, 9 deletions
diff --git a/lib/libalpm/pkghash.c b/lib/libalpm/pkghash.c
index 45e63082..a0e81f28 100644
--- a/lib/libalpm/pkghash.c
+++ b/lib/libalpm/pkghash.c
@@ -132,8 +132,7 @@ static alpm_pkghash_t *rehash(alpm_pkghash_t *oldhash)
newhash = _alpm_pkghash_create(newsize);
if(newhash == NULL) {
- /* creation of newhash failed, stick with old one... */
- return oldhash;
+ return NULL;
}
newhash->list = oldhash->list;
@@ -156,23 +155,29 @@ static alpm_pkghash_t *rehash(alpm_pkghash_t *oldhash)
return newhash;
}
-static alpm_pkghash_t *pkghash_add_pkg(alpm_pkghash_t *hash, alpm_pkg_t *pkg,
+static alpm_pkghash_t *pkghash_add_pkg(alpm_pkghash_t **hashref, alpm_pkg_t *pkg,
int sorted)
{
alpm_list_t *ptr;
unsigned int position;
+ alpm_pkghash_t *hash;
- if(pkg == NULL || hash == NULL) {
- return hash;
+ if(pkg == NULL || hashref == NULL || *hashref == NULL) {
+ return NULL;
}
+ hash = *hashref;
if(hash->entries >= hash->limit) {
- hash = rehash(hash);
+ if((hash = rehash(hash)) == NULL) {
+ /* resizing failed and there are no more open buckets */
+ return NULL;
+ }
+ *hashref = hash;
}
position = get_hash_position(pkg->name_hash, hash);
- MALLOC(ptr, sizeof(alpm_list_t), return hash);
+ MALLOC(ptr, sizeof(alpm_list_t), return NULL);
ptr->data = pkg;
ptr->prev = ptr;
@@ -189,12 +194,12 @@ static alpm_pkghash_t *pkghash_add_pkg(alpm_pkghash_t *hash, alpm_pkg_t *pkg,
return hash;
}
-alpm_pkghash_t *_alpm_pkghash_add(alpm_pkghash_t *hash, alpm_pkg_t *pkg)
+alpm_pkghash_t *_alpm_pkghash_add(alpm_pkghash_t **hash, alpm_pkg_t *pkg)
{
return pkghash_add_pkg(hash, pkg, 0);
}
-alpm_pkghash_t *_alpm_pkghash_add_sorted(alpm_pkghash_t *hash, alpm_pkg_t *pkg)
+alpm_pkghash_t *_alpm_pkghash_add_sorted(alpm_pkghash_t **hash, alpm_pkg_t *pkg)
{
return pkghash_add_pkg(hash, pkg, 1);
}