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 <konishi.ryusuke@gmail.com>
This commit is contained in:
Ryusuke Konishi 2026-01-19 19:39:15 +09:00
parent 783fe0a7ea
commit ac44e1f963

View File

@ -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;