Module: wine Branch: master Commit: d1c15438937b4b5f7fbb4348ebc5c9778e3544d3 URL: http://source.winehq.org/git/wine.git/?a=commit;h=d1c15438937b4b5f7fbb4348eb...
Author: Rob Shearman robertshearman@gmail.com Date: Sat Oct 18 11:51:02 2008 +0100
wrc: Check for overflows when parsing integer constants.
---
tools/wrc/parser.l | 20 +++++++++++++++++--- 1 files changed, 17 insertions(+), 3 deletions(-)
diff --git a/tools/wrc/parser.l b/tools/wrc/parser.l index 0ef1b0a..6d5189a 100644 --- a/tools/wrc/parser.l +++ b/tools/wrc/parser.l @@ -103,6 +103,7 @@ cident [a-zA-Z_][0-9a-zA-Z_]* #include <string.h> #include <ctype.h> #include <assert.h> +#include <limits.h>
#ifndef HAVE_UNISTD_H #define YY_NO_UNISTD_H @@ -295,6 +296,19 @@ static struct keyword *iskeyword(char *kw) 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) { return tBEGIN; } return tEND;
-[0-9]+[lL]? { parser_lval.num = strtoul(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[oO][0-7]+[lL]? { parser_lval.num = strtoul(yytext+2, 0, 8); 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 = xstrtoul(yytext, 0, 16); 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.