diff options
Diffstat (limited to 'config.c')
-rw-r--r-- | config.c | 56 |
1 files changed, 28 insertions, 28 deletions
@@ -1160,21 +1160,26 @@ static int git_parse_signed(const char *value, intmax_t *ret, intmax_t max) if (value && *value) { char *end; intmax_t val; - uintmax_t uval; - uintmax_t factor; + intmax_t factor; + + if (max < 0) + BUG("max must be a positive integer"); errno = 0; val = strtoimax(value, &end, 0); if (errno == ERANGE) return 0; + if (end == value) { + errno = EINVAL; + return 0; + } factor = get_unit_factor(end); if (!factor) { errno = EINVAL; return 0; } - uval = val < 0 ? -val : val; - if (unsigned_mult_overflows(factor, uval) || - factor * uval > max) { + if ((val < 0 && -max / factor > val) || + (val > 0 && max / factor < val)) { errno = ERANGE; return 0; } @@ -1193,10 +1198,19 @@ static int git_parse_unsigned(const char *value, uintmax_t *ret, uintmax_t max) uintmax_t val; uintmax_t factor; + /* negative values would be accepted by strtoumax */ + if (strchr(value, '-')) { + errno = EINVAL; + return 0; + } errno = 0; val = strtoumax(value, &end, 0); if (errno == ERANGE) return 0; + if (end == value) { + errno = EINVAL; + return 0; + } factor = get_unit_factor(end); if (!factor) { errno = EINVAL; @@ -1215,7 +1229,7 @@ static int git_parse_unsigned(const char *value, uintmax_t *ret, uintmax_t max) return 0; } -static int git_parse_int(const char *value, int *ret) +int git_parse_int(const char *value, int *ret) { intmax_t tmp; if (!git_parse_signed(value, &tmp, maximum_signed_value_of_type(int))) @@ -2392,11 +2406,6 @@ int git_configset_add_file(struct config_set *cs, const char *filename) return git_config_from_file(config_set_callback, filename, cs); } -int git_configset_add_parameters(struct config_set *cs) -{ - return git_config_from_parameters(config_set_callback, cs); -} - int git_configset_get_value(struct config_set *cs, const char *key, const char **value) { const struct string_list *values = NULL; @@ -2641,24 +2650,15 @@ int repo_config_get_pathname(struct repository *repo, /* Read values into protected_config. */ static void read_protected_config(void) { - char *xdg_config = NULL, *user_config = NULL, *system_config = NULL; - + struct config_options opts = { + .respect_includes = 1, + .ignore_repo = 1, + .ignore_worktree = 1, + .system_gently = 1, + }; git_configset_init(&protected_config); - - system_config = git_system_config(); - git_global_config(&user_config, &xdg_config); - - if (system_config) - git_configset_add_file(&protected_config, system_config); - if (xdg_config) - git_configset_add_file(&protected_config, xdg_config); - if (user_config) - git_configset_add_file(&protected_config, user_config); - git_configset_add_parameters(&protected_config); - - free(system_config); - free(xdg_config); - free(user_config); + config_with_options(config_set_callback, &protected_config, + NULL, &opts); } void git_protected_config(config_fn_t fn, void *data) |