mirror of
https://gitlab.freedesktop.org/wayland/wayland.git
synced 2026-03-17 05:34:23 -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;
|
long int ret;
|
||||||
char *end;
|
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;
|
errno = 0;
|
||||||
ret = strtol(str, &end, 10);
|
ret = strtol(str, &end, 10);
|
||||||
if (errno != 0 || end == str || *end != '\0')
|
if (errno != 0 || end == str || *end != '\0') {
|
||||||
return -1;
|
errno = prev_errno;
|
||||||
|
|
||||||
/* check range */
|
|
||||||
if (ret < 0 || ret > INT_MAX) {
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
errno = prev_errno;
|
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.
|
/* Check that the provided string will produce valid "C" identifiers.
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue