From 7f51ba99ae6db204d69ce271cd5cc4e959135738 Mon Sep 17 00:00:00 2001 From: Dan McGee Date: Sun, 8 Jan 2012 11:53:22 -0600 Subject: Fix segfaults on opening invalid archive files "invalid" in this case simply means files that may or may not be archives. Discovered via a `pacman -Sc` operation with delta files in the package cache directory, but can be triggered if any file is passed to `pacman -Ql` that isn't an archive, for instance, or if the sync database file is not an archive. Fix it up so we are more careful about calling archive_read_finish() only on archives that are valid and have not already been closed, and teach our archive open function to set the returned archive to NULL if we aren't going to be returning something valid anyway. Signed-off-by: Dan McGee --- lib/libalpm/be_sync.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'lib/libalpm/be_sync.c') diff --git a/lib/libalpm/be_sync.c b/lib/libalpm/be_sync.c index b16271bc..c4673b1b 100644 --- a/lib/libalpm/be_sync.c +++ b/lib/libalpm/be_sync.c @@ -391,7 +391,7 @@ static int sync_db_populate(alpm_db_t *db) { const char *dbpath; size_t est_count; - int count = -1, fd; + int count, fd; struct stat buf; struct archive *archive; struct archive_entry *entry; @@ -412,13 +412,14 @@ static int sync_db_populate(alpm_db_t *db) fd = _alpm_open_archive(db->handle, dbpath, &buf, &archive, ALPM_ERR_DB_OPEN); if(fd < 0) { - goto cleanup; + return -1; } est_count = estimate_package_count(&buf, archive); db->pkgcache = _alpm_pkghash_create(est_count); if(db->pkgcache == NULL) { db->handle->pm_errno = ALPM_ERR_MEMORY; + count = -1; goto cleanup; } -- cgit v1.2.3-24-g4f1b