aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorDavid Gibson <david@gibson.dropbear.id.au>2016-01-04 22:56:39 +1100
committerDavid Gibson <david@gibson.dropbear.id.au>2016-01-04 22:56:39 +1100
commitb43345039b03ac5691961e1ce37dfb8c4c03a863 (patch)
tree5bce1a9b006826b8d388c092968d68c5b264b4a0 /tests
parentd728ad59f53e72be21fe9bc419953c94aea798cc (diff)
downloaddtc-b43345039b03ac5691961e1ce37dfb8c4c03a863.tar.gz
Fix some bugs in processing of line directives
In order to work with preprocessed dts files more easily, dts will parse line number information in the form emitted by cpp. Anton Blanchard (using a fuzzer) reported that including a line number directive with a nul character (a literal nul in the input file, not a \0 sequence) would cause dtc to SEGV. I spotted several more problems on examining the code: * It modified yytext in place which seems to work, but is ugly and I'm not sure if it's safe on all lex/flex versions * The regexp used in the lexer to recognize line number information accepts strings with escape characters, but it won't process these escapes. - GNU cpp at least, will generate \ escapes in line number information, at least with files containing " or \ in the name This patch reworks the handling of line number information to address these problems. \ escapes should now be handled directly. nuls in file names (either with a literal nul in the input file, or with a \0 escape sequence) are still not permitted, but will now result in a lexical error rather than a SEGV. Reported-by: Anton Blanchard <anton@samba.org> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
Diffstat (limited to 'tests')
-rw-r--r--tests/line_directives.dts5
-rw-r--r--tests/nul-in-line-info1.dtsbin0 -> 8 bytes
-rw-r--r--tests/nul-in-line-info2.dts1
-rwxr-xr-xtests/run_tests.sh2
4 files changed, 8 insertions, 0 deletions
diff --git a/tests/line_directives.dts b/tests/line_directives.dts
index 046ef37..67b5e08 100644
--- a/tests/line_directives.dts
+++ b/tests/line_directives.dts
@@ -18,4 +18,9 @@
# 10 "qux.dts"
0x12345678
>;
+/*
+ * Check processing of escapes in filenames
+ */
+# 100 "\".dts"
+# 200 "\\.dts"
};
diff --git a/tests/nul-in-line-info1.dts b/tests/nul-in-line-info1.dts
new file mode 100644
index 0000000..ceb7261
--- /dev/null
+++ b/tests/nul-in-line-info1.dts
Binary files differ
diff --git a/tests/nul-in-line-info2.dts b/tests/nul-in-line-info2.dts
new file mode 100644
index 0000000..1157d23
--- /dev/null
+++ b/tests/nul-in-line-info2.dts
@@ -0,0 +1 @@
+# 0 "\0"
diff --git a/tests/run_tests.sh b/tests/run_tests.sh
index b40ba9c..8863c9a 100755
--- a/tests/run_tests.sh
+++ b/tests/run_tests.sh
@@ -293,6 +293,8 @@ libfdt_tests () {
run_wrap_error_test $DTC division-by-zero.dts
run_wrap_error_test $DTC bad-octal-literal.dts
run_dtc_test -I dts -O dtb nul-in-escape.dts
+ run_wrap_error_test $DTC nul-in-line-info1.dts
+ run_wrap_error_test $DTC nul-in-line-info2.dts
}
dtc_tests () {