diff options
author | morganamilo <morganamilo@gmail.com> | 2019-03-06 23:52:19 +0100 |
---|---|---|
committer | Allan McRae <allan@archlinux.org> | 2019-03-07 02:12:12 +0100 |
commit | 0113214db9a9e9ae48bffa3c3e7b39be16e8272a (patch) | |
tree | c76c612a3ae0a209ade117fbe3c301818c49015b | |
parent | d197d8ab82cf10650487518fb968067897a12775 (diff) | |
download | pacman-0113214db9a9e9ae48bffa3c3e7b39be16e8272a.tar.gz pacman-0113214db9a9e9ae48bffa3c3e7b39be16e8272a.tar.xz |
pacman: fix segfault when Usage is specified without a value
And extract all the common code to a macro.
Signed-off-by: morganamilo <morganamilo@gmail.com>
Signed-off-by: Allan McRae <allan@archlinux.org>
-rw-r--r-- | src/pacman/conf.c | 38 |
1 files changed, 20 insertions, 18 deletions
diff --git a/src/pacman/conf.c b/src/pacman/conf.c index 29f69052..cca3657e 100644 --- a/src/pacman/conf.c +++ b/src/pacman/conf.c @@ -844,28 +844,28 @@ static int _parse_repo(const char *key, char *value, const char *file, int ret = 0; config_repo_t *repo = section->repo; +#define CHECK_VALUE(val) do { \ + if(!val) { \ + pm_printf(ALPM_LOG_ERROR, _("config file %s, line %d: directive '%s' needs a value\n"), \ + file, line, key); \ + return 1; \ + } \ +} while(0) + if(strcmp(key, "Server") == 0) { - if(!value) { - pm_printf(ALPM_LOG_ERROR, _("config file %s, line %d: directive '%s' needs a value\n"), - file, line, key); - ret = 1; - } else { - repo->servers = alpm_list_add(repo->servers, strdup(value)); - } + CHECK_VALUE(value); + repo->servers = alpm_list_add(repo->servers, strdup(value)); } else if(strcmp(key, "SigLevel") == 0) { - if(!value) { - pm_printf(ALPM_LOG_ERROR, _("config file %s, line %d: directive '%s' needs a value\n"), - file, line, key); - } else { - alpm_list_t *values = NULL; - setrepeatingoption(value, "SigLevel", &values); - if(values) { - ret = process_siglevel(values, &repo->siglevel, - &repo->siglevel_mask, file, line); - FREELIST(values); - } + CHECK_VALUE(value); + alpm_list_t *values = NULL; + setrepeatingoption(value, "SigLevel", &values); + if(values) { + ret = process_siglevel(values, &repo->siglevel, + &repo->siglevel_mask, file, line); + FREELIST(values); } } else if(strcmp(key, "Usage") == 0) { + CHECK_VALUE(value); alpm_list_t *values = NULL; setrepeatingoption(value, "Usage", &values); if(values) { @@ -881,6 +881,8 @@ static int _parse_repo(const char *key, char *value, const char *file, file, line, key, repo->name); } +#undef CHECK_VALUE + return ret; } |