Commit cb3ea684 authored by Rob Shearman's avatar Rob Shearman Committed by Alexandre Julliard

widl: Check for overflow when parsing integer constants.

parent f24678b2
......@@ -47,6 +47,7 @@ double [0-9]+\.[0-9]+([eE][+-]?[0-9]+)*
#include <string.h>
#include <ctype.h>
#include <assert.h>
#include <limits.h>
#ifdef HAVE_UNISTD_H
#include <unistd.h>
......@@ -82,6 +83,19 @@ struct {
} import_stack[MAX_IMPORT_DEPTH];
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* uuid = xmalloc(sizeof(UUID));
......@@ -154,11 +168,11 @@ UUID *parse_uuid(const char *u)
return aUUID;
}
<INITIAL,ATTR>{hex} {
parser_lval.num = strtoul(yytext, NULL, 0);
parser_lval.num = xstrtoul(yytext, NULL, 0);
return aHEXNUM;
}
<INITIAL,ATTR>{int} {
parser_lval.num = strtoul(yytext, NULL, 0);
parser_lval.num = xstrtoul(yytext, NULL, 0);
return aNUM;
}
<INITIAL>{double} {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment