From 6d544984f2418ea34caab4c433580487b760362a Mon Sep 17 00:00:00 2001 From: Dan McGee Date: Fri, 19 Aug 2011 11:06:55 -0500 Subject: Be more robust when copying package data This changes the signature of _alpm_pkg_dup() to return an integer error code and provide the new package in a passed pointer argument. All callers are now more robust with checking the return value of this function to ensure a fatal error did not occur. We allow load failures to proceed as otherwise we have a chicken and egg problem- if a 'desc' local database entry is missing, the best way of restoring said file is `pacman -Sf --dbonly packagename`. This patch fixes a segfault that was occurring in this case. Fixes the segfault reported in FS#25667. Signed-off-by: Dan McGee --- lib/libalpm/add.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'lib/libalpm/add.c') diff --git a/lib/libalpm/add.c b/lib/libalpm/add.c index 8bbf1574..cb8551e8 100644 --- a/lib/libalpm/add.c +++ b/lib/libalpm/add.c @@ -468,19 +468,22 @@ static int commit_single_pkg(alpm_handle_t *handle, alpm_pkg_t *newpkg, is_upgrade = 1; /* we'll need to save some record for backup checks later */ - oldpkg = _alpm_pkg_dup(local); + if(_alpm_pkg_dup(local, &oldpkg) == -1) { + ret = -1; + goto cleanup; + } - EVENT(trans, ALPM_TRANS_EVT_UPGRADE_START, newpkg, oldpkg); + EVENT(trans, ALPM_TRANS_EVT_UPGRADE_START, newpkg, local); _alpm_log(handle, ALPM_LOG_DEBUG, "upgrading package %s-%s\n", newpkg->name, newpkg->version); /* copy over the install reason */ - newpkg->reason = alpm_pkg_get_reason(oldpkg); + newpkg->reason = alpm_pkg_get_reason(local); /* pre_upgrade scriptlet */ if(alpm_pkg_has_scriptlet(newpkg) && !(trans->flags & ALPM_TRANS_FLAG_NOSCRIPTLET)) { _alpm_runscriptlet(handle, newpkg->origin_data.file, - "pre_upgrade", newpkg->version, oldpkg->version); + "pre_upgrade", newpkg->version, local->version); } } else { is_upgrade = 0; -- cgit v1.2.3-24-g4f1b