From be9a60a338fd8591918711f5e826012a0d83136e Mon Sep 17 00:00:00 2001 From: Pang Yan Han Date: Tue, 8 Feb 2011 06:59:04 +0800 Subject: Handle null pkgcache for local/sync db_populate() In sync_db_populate() and local_db_populate(), a NULL db->pkgcache is not caught, allowing the functions to continue instead of exiting. A later alpm_list_msort() call which uses alpm_list_nth() will thus traverse invalid pointers in a non-existent db->pkgcache->list. pm_errno is set to PM_ERR_MEMORY as _alpm_pkghash_create() will only return NULL when we run out of memory / exceed max hash table size. The local/sync db_populate() functions are also exited. Signed-off-by: Pang Yan Han Signed-off-by: Dan McGee --- lib/libalpm/be_local.c | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'lib/libalpm/be_local.c') diff --git a/lib/libalpm/be_local.c b/lib/libalpm/be_local.c index c5b24982..58582705 100644 --- a/lib/libalpm/be_local.c +++ b/lib/libalpm/be_local.c @@ -393,6 +393,10 @@ static int local_db_populate(pmdb_t *db) /* initialize hash at 50% full */ db->pkgcache = _alpm_pkghash_create(est_count * 2); + if(db->pkgcache == NULL){ + closedir(dbdir); + RET_ERR(PM_ERR_MEMORY, -1); + } while((ent = readdir(dbdir)) != NULL) { const char *name = ent->d_name; -- cgit v1.2.3