Skip to contentSkip to conversation

Embedded NUL (again)

PATCH In review Jack Miller 2 participants 3 messages Aug 6, 2014 – Aug 8, 2014 2 messages not in the archive

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): 1407358323-14044-1-git-send-email-jack-jZyo8ZIaZD9AfugRpC6u6w@public.gmane.org

#2 lore raw

PATCH 1/1 Properly handle embedded nul delimited string lists

For example:

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

Where \0 is an actual embedded NUL in the source instead of a string escape. To achieve this, use the len given by the lexer instead of strlen.

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

---
 data.c                       |   2 +-
 tests/embedded_nul.dts       | Bin 0 -> 152 bytes
 tests/embedded_nul_equiv.dts |   6 ++++++
 tests/run_tests.sh           |   4 ++++
 4 files changed, 11 insertions(+), 1 deletion(-)
 create mode 100644 tests/embedded_nul.dts
 create mode 100644 tests/embedded_nul_equiv.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/embedded_nul.dts new file binary +0 -0
new file mode 100644
index 0000000000000000000000000000000000000000..7b4993cc5452ba57f78cedf01715deaba55d8613
GIT binary patch
tests/embedded_nul_equiv.dts new file +6 -0
new file mode 100644
index 0000000..e978204
@@ -0,0 +1,6 @@
+/dts-v1/;
+
+/ {
+	reserved-names = "aaaaaaaaaaaaaaaaaa\0bbbbbb\0ccccccccccccc";
+	reserved-ranges = < 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0  >;
+};
tests/run_tests.sh +4 -0
index f94d361..ace6e4f 100755
@@ -275,6 +275,10 @@ libfdt_tests () {
     run_dtc_test -I dts -O dtb -o sourceoutput.test.dtb sourceoutput.dts
     run_dtc_test -I dts -O dtb -o sourceoutput.test.dts.test.dtb sourceoutput.test.dts
     run_test dtbs_equal_ordered sourceoutput.test.dtb sourceoutput.test.dts.test.dtb
+
+    run_dtc_test -I dts -O dtb -o embedded_nul.test.dtb embedded_nul.dts
+    run_dtc_test -I dts -O dtb -o embedded_nul_equiv.test.dtb embedded_nul_equiv.dts
+    run_test dtbs_equal_ordered embedded_nul.test.dtb embedded_nul_equiv.test.dtb
 }
 
 dtc_tests () {
Signature · 6 lines
2.0.4

--
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

A message that is not in the archive (sent off-list or not yet received): 1407358323-14044-2-git-send-email-jack-jZyo8ZIaZD9AfugRpC6u6w@public.gmane.org

#4 lore raw

Re: [PATCH] Properly handle embedded nul delimited string lists

Quoted 10 lines · Jack Miller

For example:

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

Where \0 is an actual embedded NUL in the source instead of a string escape. To achieve this, use the len given by the lexer instead of strlen.

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

Looks good to me. Applied, thanks.

Signature · 4 lines
David Gibson			| I'll have my music baroque, and my code
david AT gibson.dropbear.id.au	| minimalist, thank you.  NOT _the_ _other_
				| _way_ _around_!
http://www.ozlabs.org/~dgibson