From ac44e1f963a7daaf7cfe91cdc85456fcb97dd3a8 Mon Sep 17 00:00:00 2001 From: Ryusuke Konishi Date: Mon, 19 Jan 2026 19:39:15 +0900 Subject: [PATCH] libparser: reject negative values in nilfs_parse_protection_period() strtoull() converts negative strings to large unsigned integers, causing inputs like "-1" to result in confusing "value too large" errors (ERANGE). Fix this by explicitly checking for a minus sign and setting errno to EINVAL, ensuring negative inputs are treated as invalid format errors. Signed-off-by: Ryusuke Konishi --- lib/parser.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/lib/parser.c b/lib/parser.c index 452508d..20a34be 100644 --- a/lib/parser.c +++ b/lib/parser.c @@ -108,6 +108,15 @@ int nilfs_parse_protection_period(const char *arg, unsigned long *period) char *endptr; int ret = 0; + while (isspace(*arg)) + arg++; + + if (*arg == '-') { + errno = EINVAL; + ret = -1; + goto out; + } + val = strtoull(arg, &endptr, 10); if (endptr == arg) { errno = EINVAL;