aboutsummaryrefslogtreecommitdiff
path: root/dtc-lexer.l
diff options
context:
space:
mode:
authorDavid Gibson <david@gibson.dropbear.id.au>2016-01-03 22:54:37 +1100
committerDavid Gibson <david@gibson.dropbear.id.au>2016-01-03 22:54:37 +1100
commit1ab2205a6f0f9e826a623e639da02787d372de37 (patch)
tree2ee7499f55e19cf77fa57e2a13ac42847f5dbd2d /dtc-lexer.l
parent19370955884ff0c49328956227c302225f4a014b (diff)
downloaddtc-1ab2205a6f0f9e826a623e639da02787d372de37.zip
dtc-1ab2205a6f0f9e826a623e639da02787d372de37.tar.gz
dtc-1ab2205a6f0f9e826a623e639da02787d372de37.tar.bz2
Gracefully handle bad octal literals
The code handling integer literals in dtc-lexer.l assumes that the flex regexp means that strtoull() can't fail to interpret the string as a valid integer (either decimal, octal, or hexadecimal). This is not true for octals. For example '09' is accepted as a literal by the regexp, strtoull() attempts to handle it as octal, but it has a bad digit. This changes the code to give a more useful error in this case. Reported-by: Anton Blanchard <anton@samba.org> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
Diffstat (limited to 'dtc-lexer.l')
-rw-r--r--dtc-lexer.l5
1 files changed, 4 insertions, 1 deletions
diff --git a/dtc-lexer.l b/dtc-lexer.l
index 0ee1caf..22dda7d 100644
--- a/dtc-lexer.l
+++ b/dtc-lexer.l
@@ -153,7 +153,10 @@ static void lexical_error(const char *fmt, ...);
errno = 0;
yylval.integer = strtoull(yytext, &e, 0);
- assert(!(*e) || !e[strspn(e, "UL")]);
+ if (*e && e[strspn(e, "UL")]) {
+ lexical_error("Bad integer literal '%s'",
+ yytext);
+ }
if (errno == ERANGE)
lexical_error("Integer literal '%s' out of range",