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>
This commit is contained in:
parent
d197d8ab82
commit
0113214db9
1 changed files with 20 additions and 18 deletions
|
@ -844,19 +844,19 @@ 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 {
|
||||
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 {
|
||||
CHECK_VALUE(value);
|
||||
alpm_list_t *values = NULL;
|
||||
setrepeatingoption(value, "SigLevel", &values);
|
||||
if(values) {
|
||||
|
@ -864,8 +864,8 @@ static int _parse_repo(const char *key, char *value, const char *file,
|
|||
&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;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue