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.
pmerrno 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.
db->pkgcache_loaded is initialized to 0 in _alpm_db_new() as
this value is used to ascertain the whether db->pkgcache is
loaded.
Signed-off-by: Pang Yan Han <pangyanhan@gmail.com>
---
lib/libalpm/be_local.c | 4 ++++
lib/libalpm/be_sync.c | 8 +++++++-
lib/libalpm/db.c | 1 +
3 files changed, 12 insertions(+), 1 deletions(-)
diff --git a/lib/libalpm/be_local.c b/lib/libalpm/be_local.c
index c5b2498..5858270 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)
On Mon, Feb 7, 2011 at 4:59 PM, Pang Yan Han <pangyanhan@gmail.com> wrote:
> 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.
>
> pmerrno 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.
>
> db->pkgcache_loaded is initialized to 0 in _alpm_db_new() as
> this value is used to ascertain the whether db->pkgcache is
> loaded.
Note that this an unnecessary addition; the use of CALLOC guarantees
all fields are zeroed out when we get the chunk of memory. I'll patch
this out when I apply this, the rest looks fine.