[pacman-dev] [PATCH 1/4] check dep versions before calling strcmp
Fixes a segfault when trying to remove an assumeinstalled option without a version. Signed-off-by: Andrew Gregory <andrew.gregory.8@gmail.com> --- lib/libalpm/handle.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/lib/libalpm/handle.c b/lib/libalpm/handle.c index 4915d0b..1be2484 100644 --- a/lib/libalpm/handle.c +++ b/lib/libalpm/handle.c @@ -606,10 +606,21 @@ static int assumeinstalled_cmp(const void *d1, const void *d2) const alpm_depend_t *dep1 = d1; const alpm_depend_t *dep2 = d2; - if(strcmp(dep1->name, dep2->name) == 0 && strcmp(dep1->version, dep2->version) == 0) { + if(dep1->name_hash != dep2->name_hash + || strcmp(dep1->name, dep2->name) != 0) { + return -1; + } + + if(dep1->version && dep2->version + && strcmp(dep1->version, dep2->version) == 0) { return 0; } + if(dep1->version == NULL && dep2->version == NULL) { + return 0; + } + + return -1; } -- 2.4.6
assumeinstalled options are used as provisions for which MOD_EQ and MOD_ANY are the only meaningful settings. Signed-off-by: Andrew Gregory <andrew.gregory.8@gmail.com> --- lib/libalpm/handle.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/libalpm/handle.c b/lib/libalpm/handle.c index 1be2484..15c60cd 100644 --- a/lib/libalpm/handle.c +++ b/lib/libalpm/handle.c @@ -585,6 +585,8 @@ int SYMEXPORT alpm_option_remove_ignoregroup(alpm_handle_t *handle, const char * int SYMEXPORT alpm_option_add_assumeinstalled(alpm_handle_t *handle, const alpm_depend_t *dep) { CHECK_HANDLE(handle, return -1); + ASSERT(dep->mod == ALPM_DEP_MOD_EQ || dep->mod == ALPM_DEP_MOD_ANY, + RET_ERR(handle, ALPM_ERR_WRONG_ARGS, -1)); handle->assumeinstalled = alpm_list_add(handle->assumeinstalled, (void *)dep); return 0; -- 2.4.6
On 17/07/15 09:05, Andrew Gregory wrote:
assumeinstalled options are used as provisions for which MOD_EQ and MOD_ANY are the only meaningful settings.
Signed-off-by: Andrew Gregory <andrew.gregory.8@gmail.com> ---
Ack.
All other option setters copy their input. Signed-off-by: Andrew Gregory <andrew.gregory.8@gmail.com> --- lib/libalpm/handle.c | 11 +++++++++-- src/pacman/conf.c | 2 +- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/lib/libalpm/handle.c b/lib/libalpm/handle.c index 15c60cd..02af2dc 100644 --- a/lib/libalpm/handle.c +++ b/lib/libalpm/handle.c @@ -584,11 +584,13 @@ int SYMEXPORT alpm_option_remove_ignoregroup(alpm_handle_t *handle, const char * int SYMEXPORT alpm_option_add_assumeinstalled(alpm_handle_t *handle, const alpm_depend_t *dep) { + alpm_depend_t *depcpy; CHECK_HANDLE(handle, return -1); ASSERT(dep->mod == ALPM_DEP_MOD_EQ || dep->mod == ALPM_DEP_MOD_ANY, RET_ERR(handle, ALPM_ERR_WRONG_ARGS, -1)); + ASSERT((depcpy = _alpm_dep_dup(dep)), RET_ERR(handle, ALPM_ERR_MEMORY, -1)); - handle->assumeinstalled = alpm_list_add(handle->assumeinstalled, (void *)dep); + handle->assumeinstalled = alpm_list_add(handle->assumeinstalled, depcpy); return 0; } @@ -599,7 +601,12 @@ int SYMEXPORT alpm_option_set_assumeinstalled(alpm_handle_t *handle, alpm_list_t alpm_list_free_inner(handle->assumeinstalled, (alpm_list_fn_free)alpm_dep_free); alpm_list_free(handle->assumeinstalled); } - handle->assumeinstalled = deps; + while(deps) { + if(alpm_option_add_assumeinstalled(handle, deps->data) != 0) { + return -1; + } + deps = deps->next; + } return 0; } diff --git a/src/pacman/conf.c b/src/pacman/conf.c index ccf8183..8616fed 100644 --- a/src/pacman/conf.c +++ b/src/pacman/conf.c @@ -797,9 +797,9 @@ static int setup_libalpm(void) pm_printf(ALPM_LOG_DEBUG, "parsed assume installed: %s %s\n", dep->name, dep->version); ret = alpm_option_add_assumeinstalled(handle, dep); + alpm_dep_free(dep); if(ret) { pm_printf(ALPM_LOG_ERROR, _("Failed to pass %s entry to libalpm"), "assume-installed"); - alpm_dep_free(dep); return ret; } } -- 2.4.6
On 17/07/15 09:05, Andrew Gregory wrote:
All other option setters copy their input.
Signed-off-by: Andrew Gregory <andrew.gregory.8@gmail.com>
Seems reasonable. A
alpm_depend_t is an exposed data type. Front-ends may opt for alloc'ing one and filling the fields manually, but alpm's _alpm_hash_sdbm is not exposed, making it impossible for them to fill in the name_hash field. Signed-off-by: Andrew Gregory <andrew.gregory.8@gmail.com> --- lib/libalpm/handle.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/libalpm/handle.c b/lib/libalpm/handle.c index 02af2dc..babd49d 100644 --- a/lib/libalpm/handle.c +++ b/lib/libalpm/handle.c @@ -590,6 +590,8 @@ int SYMEXPORT alpm_option_add_assumeinstalled(alpm_handle_t *handle, const alpm_ RET_ERR(handle, ALPM_ERR_WRONG_ARGS, -1)); ASSERT((depcpy = _alpm_dep_dup(dep)), RET_ERR(handle, ALPM_ERR_MEMORY, -1)); + /* fill in name_hash in case dep was built by hand */ + depcpy->name_hash = _alpm_hash_sdbm(dep->name); handle->assumeinstalled = alpm_list_add(handle->assumeinstalled, depcpy); return 0; } -- 2.4.6
On 17/07/15 09:05, Andrew Gregory wrote:
Fixes a segfault when trying to remove an assumeinstalled option without a version.
Signed-off-by: Andrew Gregory <andrew.gregory.8@gmail.com>
Ack.
participants (2)
-
Allan McRae
-
Andrew Gregory