Skip to contentSkip to conversation

Properly handle nul delimited string lists

PATCH New Jack Miller 1 participant 1 message Jun 24, 2014

lore
Share & tools
lore
#0 lore raw

PATCH 2/2 Properly handle nul delimited string lists

reserved-names="res1\0res2\0res3";

Where \0 is a true embedded nul in the DTS source, should properly turn into a string list. To achieve this, use the len given by the lexer instead of strlen.

Without this patch dtc will mangle the output and possible hang on realloc.

---
 data.c                    |   2 +-
 tests/nul_string_list.dtb | Bin 0 -> 127 bytes
 tests/nul_string_list.dts | Bin 0 -> 66 bytes
 tests/run_tests.sh        |   3 +++
 4 files changed, 4 insertions(+), 1 deletion(-)
 create mode 100644 tests/nul_string_list.dtb
 create mode 100644 tests/nul_string_list.dts
data.c +1 -1
index 4c50b12..8cae237 100644
@@ -74,7 +74,7 @@ struct data data_copy_escape_string(const char *s, int len)
 	struct data d;
 	char *q;
 
-	d = data_grow_for(empty_data, strlen(s)+1);
+	d = data_grow_for(empty_data, len + 1);
 
 	q = d.val;
 	while (i < len) {
tests/nul_string_list.dtb new file binary +0 -0
new file mode 100644
index 0000000000000000000000000000000000000000..ea2bc3915d8129c849d2cc7b247bc9d1a201256c
GIT binary patch
tests/nul_string_list.dts new file binary +0 -0
new file mode 100644
index 0000000000000000000000000000000000000000..845a14425fd36db3fac2934d1412dbb2cd8fb3a9
GIT binary patch
tests/run_tests.sh +3 -0
index f94d361..94b462a 100755
@@ -321,6 +321,9 @@ dtc_tests () {
     run_dtc_test -I dts -O dtb -o dtc_comments-cmp.test.dtb comments-cmp.dts
     run_test dtbs_equal_ordered dtc_comments.test.dtb dtc_comments-cmp.test.dtb
 
+    run_dtc_test -I dts -O dtb -o dtc_nul_string_list.test.dtb nul_string_list.dts
+    run_test dtbs_equal_ordered dtc_nul_string_list.test.dtb nul_string_list.dtb
+
     # Check aliases support in fdt_path_offset
     run_dtc_test -I dts -O dtb -o aliases.dtb aliases.dts
     run_test get_alias aliases.dtb
Signature · 6 lines
2.0.0

--
To unsubscribe from this list: send the line "unsubscribe devicetree-compiler" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html