aboutsummaryrefslogtreecommitdiffstats
path: root/scripts/dtc/dtc-lexer.l
diff options
context:
space:
mode:
authorRob Herring <robh@kernel.org>2016-01-26 09:04:11 -0600
committerRob Herring <robh@kernel.org>2016-02-11 19:45:09 -0600
commit91feabc2e2240ee80dc8ac08103cb83f497e4d12 (patch)
tree8bd53e02910f0d15b3516d7af298b03b19ca5dac /scripts/dtc/dtc-lexer.l
parentARM: boot: Add an implementation of strnlen for libfdt (diff)
downloadlinux-dev-91feabc2e2240ee80dc8ac08103cb83f497e4d12.tar.xz
linux-dev-91feabc2e2240ee80dc8ac08103cb83f497e4d12.zip
scripts/dtc: Update to upstream commit b06e55c88b9b
Sync to upstream dtc commit b06e55c88b9b ("Prevent crash on modulo by zero"). This adds the following commits from upstream: b06e55c Prevent crash on modulo by zero b433450 Fix some bugs in processing of line directives d728ad5 Fix crash on nul character in string escape sequence 1ab2205 Gracefully handle bad octal literals 1937095 Prevent crash on division by zero d0b3ab0 libfdt: Fix undefined behaviour in fdt_offset_ptr() d4c7c25 libfdt: check for potential overrun in _fdt_splice() f58799b libfdt: Add some missing symbols to version.lds af9f26d Remove duplicated -Werror in dtc Makefile 604e61e fdt: Add functions to retrieve strings 8702bd1 fdt: Add a function to get the index of a string 2218387 fdt: Add a function to count strings 554fde2 libfdt: fix comment block of fdt_get_property_namelen() e5e6df7 fdtdump: Fix bug printing bytestrings with negative values 067829e Remove redundant fdtdump test code 897a429 Move fdt_path_offset alias tests to right tests section 2d1417c Add simple .travis.yml f6dbc6c guess output file format 5e78dff guess input file format based on file content or file name 8b927bf tests: convert `echo -n` to `printf` 64c46b0 Fix crash with poorly defined #size-cells Cc: Grant Likely <grant.likely@linaro.org> Tested-by: Frank Rowand <frank.rowand@sonymobile.com> Reviewed-by: Frank Rowand <frank.rowand@sonymobile.com> Signed-off-by: Rob Herring <robh@kernel.org>
Diffstat (limited to 'scripts/dtc/dtc-lexer.l')
-rw-r--r--scripts/dtc/dtc-lexer.l39
1 files changed, 25 insertions, 14 deletions
diff --git a/scripts/dtc/dtc-lexer.l b/scripts/dtc/dtc-lexer.l
index 0ee1caf03dd0..790fbf6cf2d7 100644
--- a/scripts/dtc/dtc-lexer.l
+++ b/scripts/dtc/dtc-lexer.l
@@ -73,24 +73,32 @@ static void lexical_error(const char *fmt, ...);
}
<*>^"#"(line)?[ \t]+[0-9]+[ \t]+{STRING}([ \t]+[0-9]+)? {
- char *line, *tmp, *fn;
+ char *line, *fnstart, *fnend;
+ struct data fn;
/* skip text before line # */
line = yytext;
while (!isdigit((unsigned char)*line))
line++;
- /* skip digits in line # */
- tmp = line;
- while (!isspace((unsigned char)*tmp))
- tmp++;
- /* "NULL"-terminate line # */
- *tmp = '\0';
- /* start of filename */
- fn = strchr(tmp + 1, '"') + 1;
- /* strip trailing " from filename */
- tmp = strchr(fn, '"');
- *tmp = 0;
+
+ /* regexp ensures that first and list "
+ * in the whole yytext are those at
+ * beginning and end of the filename string */
+ fnstart = memchr(yytext, '"', yyleng);
+ for (fnend = yytext + yyleng - 1;
+ *fnend != '"'; fnend--)
+ ;
+ assert(fnstart && fnend && (fnend > fnstart));
+
+ fn = data_copy_escape_string(fnstart + 1,
+ fnend - fnstart - 1);
+
+ /* Don't allow nuls in filenames */
+ if (memchr(fn.val, '\0', fn.len - 1))
+ lexical_error("nul in line number directive");
+
/* -1 since #line is the number of the next line */
- srcpos_set_line(xstrdup(fn), atoi(line) - 1);
+ srcpos_set_line(xstrdup(fn.val), atoi(line) - 1);
+ data_free(fn);
}
<*><<EOF>> {
@@ -153,7 +161,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",