mirror of
https://gitlab.freedesktop.org/wayland/wayland.git
synced 2025-10-29 05:40:16 -04:00
scanner: Stricter strtouint
This helps catch bad version numbers. Signed-off-by: Demi Marie Obenour <demiobenour@gmail.com>
This commit is contained in:
parent
3dc97759fd
commit
60b34a6fcb
1 changed files with 14 additions and 8 deletions
|
|
@ -616,20 +616,26 @@ strtouint(const char *str)
|
|||
{
|
||||
long int ret;
|
||||
char *end;
|
||||
int prev_errno = errno;
|
||||
int prev_errno;
|
||||
|
||||
if (str[0] == '0')
|
||||
return str[1] ? -1 : 0;
|
||||
if (str[0] < '1' || str[0] > '9')
|
||||
return -1;
|
||||
|
||||
prev_errno = errno;
|
||||
errno = 0;
|
||||
ret = strtol(str, &end, 10);
|
||||
if (errno != 0 || end == str || *end != '\0')
|
||||
return -1;
|
||||
|
||||
/* check range */
|
||||
if (ret < 0 || ret > INT_MAX) {
|
||||
if (errno != 0 || end == str || *end != '\0') {
|
||||
errno = prev_errno;
|
||||
return -1;
|
||||
}
|
||||
|
||||
errno = prev_errno;
|
||||
return (int)ret;
|
||||
|
||||
if (ret <= 0)
|
||||
abort(); /* caught by syntax checks */
|
||||
|
||||
return ret > INT_MAX ? -1 : ret;
|
||||
}
|
||||
|
||||
/* Check that the provided string will produce valid "C" identifiers.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue