From: Jo-Philipp Wich Date: Thu, 17 Jan 2019 20:37:09 +0000 (+0100) Subject: libopkg: fix segmentation fault when traversing conflicts X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=9dd9a07600593cdbdfc4186bc5105bd6e40dbe1f;p=oweals%2Fopkg-lede.git libopkg: fix segmentation fault when traversing conflicts Signed-off-by: Jo-Philipp Wich --- diff --git a/libopkg/pkg_depends.c b/libopkg/pkg_depends.c index 9fc7251..748b599 100644 --- a/libopkg/pkg_depends.c +++ b/libopkg/pkg_depends.c @@ -466,20 +466,14 @@ int pkg_replaces(pkg_t * pkg, pkg_t * replacee) */ int pkg_conflicts_abstract(pkg_t * pkg, abstract_pkg_t * conflictee) { - compound_depend_t *conflicts, *conflict; - - conflicts = pkg_get_ptr(pkg, PKG_CONFLICTS); + int i, j; + compound_depend_t *conflicts; - int j; - for (conflict = conflicts; conflict->type; conflict++) { - int possibility_count = conflict->possibility_count; - struct depend **possibilities = conflict->possibilities; - for (j = 0; j < possibility_count; j++) { - if (possibilities[j]->pkg == conflictee) { + for (conflicts = pkg_get_ptr(pkg, PKG_CONFLICTS), i = 0; conflicts && conflicts[i].type; i++) + for (j = 0; j < conflicts[i].possibility_count; j++) + if (conflicts[i].possibilities[j]->pkg == conflictee) return 1; - } - } - } + return 0; } @@ -489,27 +483,16 @@ int pkg_conflicts_abstract(pkg_t * pkg, abstract_pkg_t * conflictee) */ int pkg_conflicts(pkg_t * pkg, pkg_t * conflictee) { - int j; - int possibility_count; - struct depend **possibilities; - compound_depend_t *conflicts, *conflict; - abstract_pkg_t **conflictee_provides, **provider, *possibility; + int i, j; + compound_depend_t *conflicts; + abstract_pkg_t **provider; - conflicts = pkg_get_ptr(pkg, PKG_CONFLICTS); - conflictee_provides = pkg_get_ptr(conflictee, PKG_PROVIDES); - - for (conflict = conflicts; conflict->type; conflict++) { - possibility_count = conflict->possibility_count; - possibilities = conflict->possibilities; - for (j = 0; j < possibility_count; j++) { - possibility = possibilities[j]->pkg; - for (provider = conflictee_provides; provider && *provider; provider++) { - if (possibility == *provider) { + for (conflicts = pkg_get_ptr(pkg, PKG_CONFLICTS), i = 0; conflicts && conflicts[i].type; i++) + for (j = 0; j < conflicts[i].possibility_count; j++) + for (provider = pkg_get_ptr(conflictee, PKG_PROVIDES); provider && *provider; provider++) + if (conflicts[i].possibilities[j]->pkg == *provider) return 1; - } - } - } - } + return 0; }