lib/, src/: Fix error handling after strto[u]l[l](3)
- Set errno = 0 before the call. Otherwise, it may contain anything. - ERANGE is not the only possible errno value of these functions. They can also set it to EINVAL. - Any errno value after these calls is bad; just compare against 0. - Don't check for the return value; just errno. This function is guaranteed to not modify errno on success (POSIX). - Check endptr == str, which may or may not set EINVAL. Suggested-by: Iker Pedrosa <ipedrosa@redhat.com> Signed-off-by: Alejandro Colomar <alx@kernel.org>
This commit is contained in:
committed by
Iker Pedrosa
parent
f6701d3efa
commit
1c464d9a2d
+2
-2
@@ -318,13 +318,13 @@ static struct ulong_range getulong_range(const char *str)
|
||||
|
||||
errno = 0;
|
||||
first = strtoll(str, &pos, 10);
|
||||
if (('\0' == *str) || ('-' != *pos ) || (ERANGE == errno) ||
|
||||
if (('\0' == *str) || ('-' != *pos ) || (0 != errno) ||
|
||||
(first != (unsigned long)first))
|
||||
goto out;
|
||||
|
||||
errno = 0;
|
||||
last = strtoll(pos + 1, &pos, 10);
|
||||
if (('\0' != *pos ) || (ERANGE == errno) ||
|
||||
if (('\0' != *pos ) || (0 != errno) ||
|
||||
(last != (unsigned long)last))
|
||||
goto out;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user