Skip to content

Commit 91feabc

Browse files
committed
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>
1 parent 76df698 commit 91feabc

12 files changed

Lines changed: 390 additions & 111 deletions

File tree

‎scripts/dtc/checks.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -560,7 +560,7 @@ static void check_reg_format(struct check *c, struct node *dt,
560560
size_cells = node_size_cells(node->parent);
561561
entrylen = (addr_cells + size_cells) * sizeof(cell_t);
562562

563-
if ((prop->val.len % entrylen) != 0)
563+
if (!entrylen || (prop->val.len % entrylen) != 0)
564564
FAIL(c, "\"reg\" property in %s has invalid length (%d bytes) "
565565
"(#address-cells == %d, #size-cells == %d)",
566566
node->fullpath, prop->val.len, addr_cells, size_cells);

‎scripts/dtc/dtc-lexer.l‎

Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -73,24 +73,32 @@ static void lexical_error(const char *fmt, ...);
7373
}
7474

7575
<*>^"#"(line)?[ \t]+[0-9]+[ \t]+{STRING}([ \t]+[0-9]+)? {
76-
char *line, *tmp, *fn;
76+
char *line, *fnstart, *fnend;
77+
struct data fn;
7778
/* skip text before line # */
7879
line = yytext;
7980
while (!isdigit((unsigned char)*line))
8081
line++;
81-
/* skip digits in line # */
82-
tmp = line;
83-
while (!isspace((unsigned char)*tmp))
84-
tmp++;
85-
/* "NULL"-terminate line # */
86-
*tmp = '\0';
87-
/* start of filename */
88-
fn = strchr(tmp + 1, '"') + 1;
89-
/* strip trailing " from filename */
90-
tmp = strchr(fn, '"');
91-
*tmp = 0;
82+
83+
/* regexp ensures that first and list "
84+
* in the whole yytext are those at
85+
* beginning and end of the filename string */
86+
fnstart = memchr(yytext, '"', yyleng);
87+
for (fnend = yytext + yyleng - 1;
88+
*fnend != '"'; fnend--)
89+
;
90+
assert(fnstart && fnend && (fnend > fnstart));
91+
92+
fn = data_copy_escape_string(fnstart + 1,
93+
fnend - fnstart - 1);
94+
95+
/* Don't allow nuls in filenames */
96+
if (memchr(fn.val, '\0', fn.len - 1))
97+
lexical_error("nul in line number directive");
98+
9299
/* -1 since #line is the number of the next line */
93-
srcpos_set_line(xstrdup(fn), atoi(line) - 1);
100+
srcpos_set_line(xstrdup(fn.val), atoi(line) - 1);
101+
data_free(fn);
94102
}
95103

96104
<*><<EOF>> {
@@ -153,7 +161,10 @@ static void lexical_error(const char *fmt, ...);
153161
errno = 0;
154162
yylval.integer = strtoull(yytext, &e, 0);
155163

156-
assert(!(*e) || !e[strspn(e, "UL")]);
164+
if (*e && e[strspn(e, "UL")]) {
165+
lexical_error("Bad integer literal '%s'",
166+
yytext);
167+
}
157168

158169
if (errno == ERANGE)
159170
lexical_error("Integer literal '%s' out of range",

‎scripts/dtc/dtc-lexer.lex.c_shipped‎

Lines changed: 56 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -951,31 +951,39 @@ case 2:
951951
YY_RULE_SETUP
952952
#line 75 "dtc-lexer.l"
953953
{
954-
char *line, *tmp, *fn;
954+
char *line, *fnstart, *fnend;
955+
struct data fn;
955956
/* skip text before line # */
956957
line = yytext;
957958
while (!isdigit((unsigned char)*line))
958959
line++;
959-
/* skip digits in line # */
960-
tmp = line;
961-
while (!isspace((unsigned char)*tmp))
962-
tmp++;
963-
/* "NULL"-terminate line # */
964-
*tmp = '\0';
965-
/* start of filename */
966-
fn = strchr(tmp + 1, '"') + 1;
967-
/* strip trailing " from filename */
968-
tmp = strchr(fn, '"');
969-
*tmp = 0;
960+
961+
/* regexp ensures that first and list "
962+
* in the whole yytext are those at
963+
* beginning and end of the filename string */
964+
fnstart = memchr(yytext, '"', yyleng);
965+
for (fnend = yytext + yyleng - 1;
966+
*fnend != '"'; fnend--)
967+
;
968+
assert(fnstart && fnend && (fnend > fnstart));
969+
970+
fn = data_copy_escape_string(fnstart + 1,
971+
fnend - fnstart - 1);
972+
973+
/* Don't allow nuls in filenames */
974+
if (memchr(fn.val, '\0', fn.len - 1))
975+
lexical_error("nul in line number directive");
976+
970977
/* -1 since #line is the number of the next line */
971-
srcpos_set_line(xstrdup(fn), atoi(line) - 1);
978+
srcpos_set_line(xstrdup(fn.val), atoi(line) - 1);
979+
data_free(fn);
972980
}
973981
YY_BREAK
974982
case YY_STATE_EOF(INITIAL):
975983
case YY_STATE_EOF(BYTESTRING):
976984
case YY_STATE_EOF(PROPNODENAME):
977985
case YY_STATE_EOF(V1):
978-
#line 96 "dtc-lexer.l"
986+
#line 104 "dtc-lexer.l"
979987
{
980988
if (!pop_input_file()) {
981989
yyterminate();
@@ -985,7 +993,7 @@ case YY_STATE_EOF(V1):
985993
case 3:
986994
/* rule 3 can match eol */
987995
YY_RULE_SETUP
988-
#line 102 "dtc-lexer.l"
996+
#line 110 "dtc-lexer.l"
989997
{
990998
DPRINT("String: %s\n", yytext);
991999
yylval.data = data_copy_escape_string(yytext+1,
@@ -995,7 +1003,7 @@ YY_RULE_SETUP
9951003
YY_BREAK
9961004
case 4:
9971005
YY_RULE_SETUP
998-
#line 109 "dtc-lexer.l"
1006+
#line 117 "dtc-lexer.l"
9991007
{
10001008
DPRINT("Keyword: /dts-v1/\n");
10011009
dts_version = 1;
@@ -1005,7 +1013,7 @@ YY_RULE_SETUP
10051013
YY_BREAK
10061014
case 5:
10071015
YY_RULE_SETUP
1008-
#line 116 "dtc-lexer.l"
1016+
#line 124 "dtc-lexer.l"
10091017
{
10101018
DPRINT("Keyword: /memreserve/\n");
10111019
BEGIN_DEFAULT();
@@ -1014,7 +1022,7 @@ YY_RULE_SETUP
10141022
YY_BREAK
10151023
case 6:
10161024
YY_RULE_SETUP
1017-
#line 122 "dtc-lexer.l"
1025+
#line 130 "dtc-lexer.l"
10181026
{
10191027
DPRINT("Keyword: /bits/\n");
10201028
BEGIN_DEFAULT();
@@ -1023,7 +1031,7 @@ YY_RULE_SETUP
10231031
YY_BREAK
10241032
case 7:
10251033
YY_RULE_SETUP
1026-
#line 128 "dtc-lexer.l"
1034+
#line 136 "dtc-lexer.l"
10271035
{
10281036
DPRINT("Keyword: /delete-property/\n");
10291037
DPRINT("<PROPNODENAME>\n");
@@ -1033,7 +1041,7 @@ YY_RULE_SETUP
10331041
YY_BREAK
10341042
case 8:
10351043
YY_RULE_SETUP
1036-
#line 135 "dtc-lexer.l"
1044+
#line 143 "dtc-lexer.l"
10371045
{
10381046
DPRINT("Keyword: /delete-node/\n");
10391047
DPRINT("<PROPNODENAME>\n");
@@ -1043,7 +1051,7 @@ YY_RULE_SETUP
10431051
YY_BREAK
10441052
case 9:
10451053
YY_RULE_SETUP
1046-
#line 142 "dtc-lexer.l"
1054+
#line 150 "dtc-lexer.l"
10471055
{
10481056
DPRINT("Label: %s\n", yytext);
10491057
yylval.labelref = xstrdup(yytext);
@@ -1053,15 +1061,18 @@ YY_RULE_SETUP
10531061
YY_BREAK
10541062
case 10:
10551063
YY_RULE_SETUP
1056-
#line 149 "dtc-lexer.l"
1064+
#line 157 "dtc-lexer.l"
10571065
{
10581066
char *e;
10591067
DPRINT("Integer Literal: '%s'\n", yytext);
10601068

10611069
errno = 0;
10621070
yylval.integer = strtoull(yytext, &e, 0);
10631071

1064-
assert(!(*e) || !e[strspn(e, "UL")]);
1072+
if (*e && e[strspn(e, "UL")]) {
1073+
lexical_error("Bad integer literal '%s'",
1074+
yytext);
1075+
}
10651076

10661077
if (errno == ERANGE)
10671078
lexical_error("Integer literal '%s' out of range",
@@ -1076,7 +1087,7 @@ YY_RULE_SETUP
10761087
case 11:
10771088
/* rule 11 can match eol */
10781089
YY_RULE_SETUP
1079-
#line 168 "dtc-lexer.l"
1090+
#line 179 "dtc-lexer.l"
10801091
{
10811092
struct data d;
10821093
DPRINT("Character literal: %s\n", yytext);
@@ -1100,7 +1111,7 @@ YY_RULE_SETUP
11001111
YY_BREAK
11011112
case 12:
11021113
YY_RULE_SETUP
1103-
#line 189 "dtc-lexer.l"
1114+
#line 200 "dtc-lexer.l"
11041115
{ /* label reference */
11051116
DPRINT("Ref: %s\n", yytext+1);
11061117
yylval.labelref = xstrdup(yytext+1);
@@ -1109,7 +1120,7 @@ YY_RULE_SETUP
11091120
YY_BREAK
11101121
case 13:
11111122
YY_RULE_SETUP
1112-
#line 195 "dtc-lexer.l"
1123+
#line 206 "dtc-lexer.l"
11131124
{ /* new-style path reference */
11141125
yytext[yyleng-1] = '\0';
11151126
DPRINT("Ref: %s\n", yytext+2);
@@ -1119,7 +1130,7 @@ YY_RULE_SETUP
11191130
YY_BREAK
11201131
case 14:
11211132
YY_RULE_SETUP
1122-
#line 202 "dtc-lexer.l"
1133+
#line 213 "dtc-lexer.l"
11231134
{
11241135
yylval.byte = strtol(yytext, NULL, 16);
11251136
DPRINT("Byte: %02x\n", (int)yylval.byte);
@@ -1128,7 +1139,7 @@ YY_RULE_SETUP
11281139
YY_BREAK
11291140
case 15:
11301141
YY_RULE_SETUP
1131-
#line 208 "dtc-lexer.l"
1142+
#line 219 "dtc-lexer.l"
11321143
{
11331144
DPRINT("/BYTESTRING\n");
11341145
BEGIN_DEFAULT();
@@ -1137,7 +1148,7 @@ YY_RULE_SETUP
11371148
YY_BREAK
11381149
case 16:
11391150
YY_RULE_SETUP
1140-
#line 214 "dtc-lexer.l"
1151+
#line 225 "dtc-lexer.l"
11411152
{
11421153
DPRINT("PropNodeName: %s\n", yytext);
11431154
yylval.propnodename = xstrdup((yytext[0] == '\\') ?
@@ -1148,7 +1159,7 @@ YY_RULE_SETUP
11481159
YY_BREAK
11491160
case 17:
11501161
YY_RULE_SETUP
1151-
#line 222 "dtc-lexer.l"
1162+
#line 233 "dtc-lexer.l"
11521163
{
11531164
DPRINT("Binary Include\n");
11541165
return DT_INCBIN;
@@ -1157,64 +1168,64 @@ YY_RULE_SETUP
11571168
case 18:
11581169
/* rule 18 can match eol */
11591170
YY_RULE_SETUP
1160-
#line 227 "dtc-lexer.l"
1171+
#line 238 "dtc-lexer.l"
11611172
/* eat whitespace */
11621173
YY_BREAK
11631174
case 19:
11641175
/* rule 19 can match eol */
11651176
YY_RULE_SETUP
1166-
#line 228 "dtc-lexer.l"
1177+
#line 239 "dtc-lexer.l"
11671178
/* eat C-style comments */
11681179
YY_BREAK
11691180
case 20:
11701181
/* rule 20 can match eol */
11711182
YY_RULE_SETUP
1172-
#line 229 "dtc-lexer.l"
1183+
#line 240 "dtc-lexer.l"
11731184
/* eat C++-style comments */
11741185
YY_BREAK
11751186
case 21:
11761187
YY_RULE_SETUP
1177-
#line 231 "dtc-lexer.l"
1188+
#line 242 "dtc-lexer.l"
11781189
{ return DT_LSHIFT; };
11791190
YY_BREAK
11801191
case 22:
11811192
YY_RULE_SETUP
1182-
#line 232 "dtc-lexer.l"
1193+
#line 243 "dtc-lexer.l"
11831194
{ return DT_RSHIFT; };
11841195
YY_BREAK
11851196
case 23:
11861197
YY_RULE_SETUP
1187-
#line 233 "dtc-lexer.l"
1198+
#line 244 "dtc-lexer.l"
11881199
{ return DT_LE; };
11891200
YY_BREAK
11901201
case 24:
11911202
YY_RULE_SETUP
1192-
#line 234 "dtc-lexer.l"
1203+
#line 245 "dtc-lexer.l"
11931204
{ return DT_GE; };
11941205
YY_BREAK
11951206
case 25:
11961207
YY_RULE_SETUP
1197-
#line 235 "dtc-lexer.l"
1208+
#line 246 "dtc-lexer.l"
11981209
{ return DT_EQ; };
11991210
YY_BREAK
12001211
case 26:
12011212
YY_RULE_SETUP
1202-
#line 236 "dtc-lexer.l"
1213+
#line 247 "dtc-lexer.l"
12031214
{ return DT_NE; };
12041215
YY_BREAK
12051216
case 27:
12061217
YY_RULE_SETUP
1207-
#line 237 "dtc-lexer.l"
1218+
#line 248 "dtc-lexer.l"
12081219
{ return DT_AND; };
12091220
YY_BREAK
12101221
case 28:
12111222
YY_RULE_SETUP
1212-
#line 238 "dtc-lexer.l"
1223+
#line 249 "dtc-lexer.l"
12131224
{ return DT_OR; };
12141225
YY_BREAK
12151226
case 29:
12161227
YY_RULE_SETUP
1217-
#line 240 "dtc-lexer.l"
1228+
#line 251 "dtc-lexer.l"
12181229
{
12191230
DPRINT("Char: %c (\\x%02x)\n", yytext[0],
12201231
(unsigned)yytext[0]);
@@ -1232,10 +1243,10 @@ YY_RULE_SETUP
12321243
YY_BREAK
12331244
case 30:
12341245
YY_RULE_SETUP
1235-
#line 255 "dtc-lexer.l"
1246+
#line 266 "dtc-lexer.l"
12361247
ECHO;
12371248
YY_BREAK
1238-
#line 1239 "dtc-lexer.lex.c"
1249+
#line 1250 "dtc-lexer.lex.c"
12391250

12401251
case YY_END_OF_BUFFER:
12411252
{
@@ -2195,7 +2206,7 @@ void yyfree (void * ptr )
21952206

21962207
#define YYTABLES_NAME "yytables"
21972208

2198-
#line 254 "dtc-lexer.l"
2209+
#line 265 "dtc-lexer.l"
21992210

22002211

22012212

0 commit comments

Comments
 (0)