From 683feacf378db0217b8ab421e0a694b0b68188c9 Mon Sep 17 00:00:00 2001 From: zhuofeng Date: Thu, 7 Dec 2023 14:37:50 +0800 Subject: [PATCH] Fix the bug that `config->env` is greater than `ulong_max` when units->val=1 Signed-off-by: Mauro Carvalho Chehab --- ras-page-isolation.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/ras-page-isolation.c b/ras-page-isolation.c index bb6b777..0ea36f6 100644 --- a/ras-page-isolation.c +++ b/ras-page-isolation.c @@ -157,6 +157,17 @@ static void parse_isolation_env(struct isolation *config) value *= units->val; if (tmp != 0 && value / tmp != units->val) config->overflow = true; + /** + * if units->val is 1, config->env is greater than ulong_max, so it is can strtoul + * if failed, the value is greater than ulong_max, set config->overflow = true + */ + if (units->val == 1) { + char *endptr; + unsigned long converted_value = strtoul(config->env, &endptr, 10); + if (errno == ERANGE || *endptr != '\0') + config->overflow = true; + } + unit_matched = 0; } } config->val = value;