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

wrc: Check for overflows when parsing integer constants.

parent cb3ea684
...@@ -103,6 +103,7 @@ cident [a-zA-Z_][0-9a-zA-Z_]* ...@@ -103,6 +103,7 @@ cident [a-zA-Z_][0-9a-zA-Z_]*
#include <string.h> #include <string.h>
#include <ctype.h> #include <ctype.h>
#include <assert.h> #include <assert.h>
#include <limits.h>
#ifndef HAVE_UNISTD_H #ifndef HAVE_UNISTD_H
#define YY_NO_UNISTD_H #define YY_NO_UNISTD_H
...@@ -295,6 +296,19 @@ static struct keyword *iskeyword(char *kw) ...@@ -295,6 +296,19 @@ static struct keyword *iskeyword(char *kw)
return kwp; return kwp;
} }
/* 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)
parser_error("integer constant %s is too large\n", nptr);
return l;
}
%} %}
/* /*
...@@ -378,9 +392,9 @@ static struct keyword *iskeyword(char *kw) ...@@ -378,9 +392,9 @@ static struct keyword *iskeyword(char *kw)
\{ return tBEGIN; \{ return tBEGIN;
\} return tEND; \} return tEND;
[0-9]+[lL]? { parser_lval.num = strtoul(yytext, 0, 10); return toupper(yytext[yyleng-1]) == 'L' ? tLNUMBER : tNUMBER; } [0-9]+[lL]? { parser_lval.num = xstrtoul(yytext, 0, 10); return toupper(yytext[yyleng-1]) == 'L' ? tLNUMBER : tNUMBER; }
0[xX][0-9A-Fa-f]+[lL]? { parser_lval.num = strtoul(yytext, 0, 16); return toupper(yytext[yyleng-1]) == 'L' ? tLNUMBER : tNUMBER; } 0[xX][0-9A-Fa-f]+[lL]? { parser_lval.num = xstrtoul(yytext, 0, 16); return toupper(yytext[yyleng-1]) == 'L' ? tLNUMBER : tNUMBER; }
0[oO][0-7]+[lL]? { parser_lval.num = strtoul(yytext+2, 0, 8); return toupper(yytext[yyleng-1]) == 'L' ? tLNUMBER : tNUMBER; } 0[oO][0-7]+[lL]? { parser_lval.num = xstrtoul(yytext+2, 0, 8); return toupper(yytext[yyleng-1]) == 'L' ? tLNUMBER : tNUMBER; }
/* /*
* The next two rules scan identifiers and filenames. * The next two rules scan identifiers and filenames.
......
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