widl: Check for overflow when parsing integer constants.
This commit is contained in:
parent
f24678b285
commit
cb3ea6843c
@ -47,6 +47,7 @@ double [0-9]+\.[0-9]+([eE][+-]?[0-9]+)*
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
|
#include <limits.h>
|
||||||
|
|
||||||
#ifdef HAVE_UNISTD_H
|
#ifdef HAVE_UNISTD_H
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
@ -82,6 +83,19 @@ struct {
|
|||||||
} import_stack[MAX_IMPORT_DEPTH];
|
} import_stack[MAX_IMPORT_DEPTH];
|
||||||
int import_stack_ptr = 0;
|
int import_stack_ptr = 0;
|
||||||
|
|
||||||
|
/* converts an integer in string form to an unsigned long and prints an error
|
||||||
|
* on overflow */
|
||||||
|
static unsigned long xstrtoul(const char *nptr, char **endptr, int base)
|
||||||
|
{
|
||||||
|
unsigned long l;
|
||||||
|
|
||||||
|
errno = 0;
|
||||||
|
l = strtoul(nptr, endptr, base);
|
||||||
|
if (l == ULONG_MAX && errno == ERANGE)
|
||||||
|
error_loc("integer constant %s is too large\n", nptr);
|
||||||
|
return l;
|
||||||
|
}
|
||||||
|
|
||||||
UUID *parse_uuid(const char *u)
|
UUID *parse_uuid(const char *u)
|
||||||
{
|
{
|
||||||
UUID* uuid = xmalloc(sizeof(UUID));
|
UUID* uuid = xmalloc(sizeof(UUID));
|
||||||
@ -154,11 +168,11 @@ UUID *parse_uuid(const char *u)
|
|||||||
return aUUID;
|
return aUUID;
|
||||||
}
|
}
|
||||||
<INITIAL,ATTR>{hex} {
|
<INITIAL,ATTR>{hex} {
|
||||||
parser_lval.num = strtoul(yytext, NULL, 0);
|
parser_lval.num = xstrtoul(yytext, NULL, 0);
|
||||||
return aHEXNUM;
|
return aHEXNUM;
|
||||||
}
|
}
|
||||||
<INITIAL,ATTR>{int} {
|
<INITIAL,ATTR>{int} {
|
||||||
parser_lval.num = strtoul(yytext, NULL, 0);
|
parser_lval.num = xstrtoul(yytext, NULL, 0);
|
||||||
return aNUM;
|
return aNUM;
|
||||||
}
|
}
|
||||||
<INITIAL>{double} {
|
<INITIAL>{double} {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user