]> www.infradead.org Git - users/mchehab/rasdaemon.git/commitdiff
Fix the bug that `config->env` is greater than `ulong_max` when units->val=1
authorzhuofeng <zhuofeng2@huawei.com>
Thu, 7 Dec 2023 06:37:50 +0000 (14:37 +0800)
committerMauro Carvalho Chehab <mchehab+huawei@kernel.org>
Mon, 18 Nov 2024 12:58:59 +0000 (13:58 +0100)
Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
ras-page-isolation.c

index bb6b7770b641b17702913a4fba69f7b0a975a6bf..0ea36f67b1f485c7a3a00459f95236784ccc0bbc 100644 (file)
@@ -157,6 +157,17 @@ parse:
                        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;