mirror of
https://github.com/nilfs-dev/nilfs-utils.git
synced 2026-01-26 13:43:15 +00:00
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:
parent
783fe0a7ea
commit
ac44e1f963
@ -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;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user