1
0
mirror of https://github.com/moparisthebest/pacman synced 2024-12-23 00:08:50 -05:00

Ensure dbpath is not null when populating sync database

We didn't do this sanity check before trying to open an archive. If
the alpm dbpath wasn't set, the sync database dbpath would be NULL,
causing us to hang indefinitely in archive_read_open_filename() rather
than erroring out.

We already have a corresponding check in local_db_populate().

The following program will test this case, and hangs before this patch
without the call to set_dbpath:

	int main(int argc, char *argv[]) {
		alpm_initialize();
		// alpm_option_set_dbpath("/var/lib/pacman/");
		pmdb_t *core = alpm_db_register_sync("core");
		pmpkg_t *pkg = alpm_db_get_pkg(core, "pacman");
		return 0;
	}

Signed-off-by: Dan McGee <dan@archlinux.org>
This commit is contained in:
Dan McGee 2011-04-01 14:31:50 -05:00
parent 20c4928ee1
commit 39fd8bc318

View File

@ -209,6 +209,7 @@ static size_t estimate_package_count(struct stat *st, struct archive *archive)
static int sync_db_populate(pmdb_t *db)
{
const char *dbpath;
size_t est_count;
int count = 0;
struct stat buf;
@ -226,14 +227,22 @@ static int sync_db_populate(pmdb_t *db)
archive_read_support_compression_all(archive);
archive_read_support_format_all(archive);
if(archive_read_open_filename(archive, _alpm_db_path(db),
dbpath = _alpm_db_path(db);
if(!dbpath) {
/* pm_errno set in _alpm_db_path() */
return 1;
}
_alpm_log(PM_LOG_DEBUG, "opening database archive %s\n", dbpath);
if(archive_read_open_filename(archive, dbpath,
ARCHIVE_DEFAULT_BYTES_PER_BLOCK) != ARCHIVE_OK) {
_alpm_log(PM_LOG_ERROR, _("could not open file %s: %s\n"), _alpm_db_path(db),
_alpm_log(PM_LOG_ERROR, _("could not open file %s: %s\n"), dbpath,
archive_error_string(archive));
archive_read_finish(archive);
RET_ERR(PM_ERR_DB_OPEN, 1);
}
if(stat(_alpm_db_path(db), &buf) != 0) {
if(stat(dbpath, &buf) != 0) {
RET_ERR(PM_ERR_DB_OPEN, 1);
}
est_count = estimate_package_count(&buf, archive);