From 8ee24aa26cedebad4ed99154ea162969c145a59e Mon Sep 17 00:00:00 2001 From: Andrea Mazzoleni Date: Thu, 19 Mar 2026 12:59:03 +0100 Subject: [PATCH] Avoid undefined behaviour parsing double --- cmdline/snapraid.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/cmdline/snapraid.c b/cmdline/snapraid.c index 10467af2..af1e4129 100644 --- a/cmdline/snapraid.c +++ b/cmdline/snapraid.c @@ -1100,13 +1100,17 @@ int snapraid_main(int argc, char* argv[]) plan100 = SCRUB_FULL; } else { double plan_double = strtod(optarg, &e); - plan100 = plan_double * 100; - if (!e || *e || plan100 > 10000) { + if (!e || *e != 0 + || !isfinite(plan_double) + || plan_double < 0 + || plan_double > 100 + ) { /* LCOV_EXCL_START */ log_fatal(EUSER, "Invalid plan/percentage '%s'\n", optarg); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } + plan100 = plan_double * 100; } break; case 'o' :