Improve robustness of parsing the --debug argument

Signed-off-by: Allan McRae <allan@archlinux.org>
This commit is contained in:
Allan McRae 2024-02-25 12:48:30 +10:00
parent c9c56be396
commit 5121108542

View file

@ -409,7 +409,18 @@ static int parsearg_global(int opt)
* here, error and warning are set in config_new, though perhaps a
* --quiet option will remove these later */
if(optarg) {
unsigned short debug = (unsigned short)atoi(optarg);
char *endptr;
long debug;
errno = 0;
debug = strtol(optarg, &endptr, 10);
if(errno == ERANGE || endptr == optarg || *endptr != '\0') {
pm_printf(ALPM_LOG_ERROR, _("'%s' is not a valid debug level\n"),
optarg);
return 1;
}
switch(debug) {
case 2:
config->logmask |= ALPM_LOG_FUNCTION;