Rob Shearman : widl: Check for overflow when parsing integer constants.
Alexandre Julliard
julliard at winehq.org
Sat Oct 18 13:38:55 CDT 2008
Module: wine
Branch: master
Commit: cb3ea6843cad1a28b4e9f1d67a6e539af63ec24a
URL: http://source.winehq.org/git/wine.git/?a=commit;h=cb3ea6843cad1a28b4e9f1d67a6e539af63ec24a
Author: Rob Shearman <robertshearman at gmail.com>
Date: Sat Oct 18 11:50:20 2008 +0100
widl: Check for overflow when parsing integer constants.
---
tools/widl/parser.l | 18 ++++++++++++++++--
1 files changed, 16 insertions(+), 2 deletions(-)
diff --git a/tools/widl/parser.l b/tools/widl/parser.l
index 6a02f50..15e1fb9 100644
--- a/tools/widl/parser.l
+++ b/tools/widl/parser.l
@@ -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} {
More information about the wine-cvs
mailing list