diff --git a/src/cache.c b/src/cache.c index d24115431..9070e996d 100644 --- a/src/cache.c +++ b/src/cache.c @@ -838,17 +838,32 @@ int cfg_parse_cache(const char *file, int linenum, char **args, int kwm) tmp_cache_config->maxobjsz = 0; } } else if (strcmp(args[0], "total-max-size") == 0) { - int maxsize; + unsigned long int maxsize; + char *err; if (alertif_too_many_args(1, file, linenum, args, &err_code)) { err_code |= ERR_ABORT; goto out; } - /* size in megabytes */ - maxsize = atoi(args[1]) * 1024 * 1024 / CACHE_BLOCKSIZE; - tmp_cache_config->maxblocks = maxsize; + maxsize = strtoul(args[1], &err, 10); + if (err == args[1] || *err != '\0') { + ha_warning("parsing [%s:%d]: total-max-size wrong value '%s'\n", + file, linenum, args[1]); + err_code |= ERR_ABORT; + goto out; + } + if (maxsize > (UINT_MAX >> 20)) { + ha_warning("parsing [%s:%d]: \"total-max-size\" (%s) must not be greater than %u\n", + file, linenum, args[1], UINT_MAX >> 20); + err_code |= ERR_ABORT; + goto out; + } + + /* size in megabytes */ + maxsize *= 1024 * 1024 / CACHE_BLOCKSIZE; + tmp_cache_config->maxblocks = maxsize; } else if (strcmp(args[0], "max-age") == 0) { if (alertif_too_many_args(1, file, linenum, args, &err_code)) { err_code |= ERR_ABORT;