platform_external_dtc/tests/line_directives.dts
Stephen Warren a1ee6f068e dtc: ensure #line directives don't consume data from the next line
Previously, the #line parsing regex ended with ({WS}+[0-9]+)?. The {WS}
could match line-break characters. If the #line directive did not contain
the optional flags field at the end, this could cause any integer data on
the next line to be consumed as part of the #line directive parsing. This
could cause syntax errors (i.e. #line parsing consuming the leading 0
from a hex literal 0x1234, leaving x1234 to be parsed as cell data,
which is a syntax error), or invalid compilation results (i.e. simply
consuming literal 1234 as part of the #line processing, thus removing it
from the cell data).

Fix this by replacing {WS} with [ \t] so that it can't match line-breaks.

Convert all instances of {WS}, even though the other instances should be
irrelevant for any well-formed #line directive. This is done for
consistency and ultimate safety.

Reported-by: Ian Campbell <Ian.Campbell@citrix.com>
Signed-off-by: Stephen Warren <swarren@nvidia.com>
Acked-by: David Gibson <david@gibson.dropbear.id.au>
2013-06-03 08:28:58 -05:00

21 lines
473 B
Text

/dts-v1/;
/* common format */
#line 3 "foo.dts"
/* newer gcc format */
# 9 "baz.dts" 1
/* flags are optional */
# 6 "bar.dts"
/ {
/*
* Make sure optional flags don't consume integer data on next line. The issue
* was that the {WS} in the trailing ({WS}+[0-9]+)? could cross the * line-
* break, and consume the leading "0" of the hex constant, leaving "x12345678"
* to be parsed as a number, which is invalid syntax.
*/
prop1 = <
# 10 "qux.dts"
0x12345678
>;
};