devicetree-compiler.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] Properly handle embedded nul delimited string lists
       [not found] ` <1407353512-12182-1-git-send-email-jack-jZyo8ZIaZD9AfugRpC6u6w@public.gmane.org>
@ 2014-08-06 19:31   ` Jack Miller
  0 siblings, 0 replies; 4+ messages in thread
From: Jack Miller @ 2014-08-06 19:31 UTC (permalink / raw)
  To: devicetree-compiler-u79uwXL29TY76Z2rM5mHXA

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

diff --git a/data.c b/data.c
index 4c50b12..8cae237 100644
--- a/data.c
+++ b/data.c
@@ -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) {
diff --git a/tests/embedded_nul.dts b/tests/embedded_nul.dts
new file mode 100644
index 0000000000000000000000000000000000000000..7b4993cc5452ba57f78cedf01715deaba55d8613
GIT binary patch
literal 152
zcmdN-DJj-1Gt{@{;?h^B=He_$Elw>eOHI+uOUz9zR<Ko2O2hyRNnpT`j0}{lku(=2
W=B0ym+b9@R7?6Y&?5w$Jt+@ajWGrd`

literal 0
HcmV?d00001

diff --git a/tests/embedded_nul_equiv.dts b/tests/embedded_nul_equiv.dts
new file mode 100644
index 0000000..e978204
--- /dev/null
+++ b/tests/embedded_nul_equiv.dts
@@ -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  >;
+};
diff --git a/tests/run_tests.sh b/tests/run_tests.sh
index f94d361..ace6e4f 100755
--- a/tests/run_tests.sh
+++ b/tests/run_tests.sh
@@ -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 () {
-- 
2.0.4

--
To unsubscribe from this list: send the line "unsubscribe devicetree-compiler" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Embedded NUL (again)
@ 2014-08-06 20:52 Jack Miller
       [not found] ` <1407358323-14044-1-git-send-email-jack-jZyo8ZIaZD9AfugRpC6u6w@public.gmane.org>
  0 siblings, 1 reply; 4+ messages in thread
From: Jack Miller @ 2014-08-06 20:52 UTC (permalink / raw)
  To: devicetree-compiler-u79uwXL29TY76Z2rM5mHXA

This fell out of my scope for a while, but I think this one should be golden.

-Jack

--
To unsubscribe from this list: send the line "unsubscribe devicetree-compiler" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH] Properly handle embedded nul delimited string lists
       [not found] ` <1407358323-14044-1-git-send-email-jack-jZyo8ZIaZD9AfugRpC6u6w@public.gmane.org>
@ 2014-08-06 20:52   ` Jack Miller
       [not found]     ` <1407358323-14044-2-git-send-email-jack-jZyo8ZIaZD9AfugRpC6u6w@public.gmane.org>
  0 siblings, 1 reply; 4+ messages in thread
From: Jack Miller @ 2014-08-06 20:52 UTC (permalink / raw)
  To: devicetree-compiler-u79uwXL29TY76Z2rM5mHXA

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

diff --git a/data.c b/data.c
index 4c50b12..8cae237 100644
--- a/data.c
+++ b/data.c
@@ -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) {
diff --git a/tests/embedded_nul.dts b/tests/embedded_nul.dts
new file mode 100644
index 0000000000000000000000000000000000000000..7b4993cc5452ba57f78cedf01715deaba55d8613
GIT binary patch
literal 152
zcmdN-DJj-1Gt{@{;?h^B=He_$Elw>eOHI+uOUz9zR<Ko2O2hyRNnpT`j0}{lku(=2
W=B0ym+b9@R7?6Y&?5w$Jt+@ajWGrd`

literal 0
HcmV?d00001

diff --git a/tests/embedded_nul_equiv.dts b/tests/embedded_nul_equiv.dts
new file mode 100644
index 0000000..e978204
--- /dev/null
+++ b/tests/embedded_nul_equiv.dts
@@ -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  >;
+};
diff --git a/tests/run_tests.sh b/tests/run_tests.sh
index f94d361..ace6e4f 100755
--- a/tests/run_tests.sh
+++ b/tests/run_tests.sh
@@ -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 () {
-- 
2.0.4

--
To unsubscribe from this list: send the line "unsubscribe devicetree-compiler" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] Properly handle embedded nul delimited string lists
       [not found]     ` <1407358323-14044-2-git-send-email-jack-jZyo8ZIaZD9AfugRpC6u6w@public.gmane.org>
@ 2014-08-08  9:18       ` David Gibson
  0 siblings, 0 replies; 4+ messages in thread
From: David Gibson @ 2014-08-08  9:18 UTC (permalink / raw)
  To: Jack Miller; +Cc: devicetree-compiler-u79uwXL29TY76Z2rM5mHXA

[-- Attachment #1: Type: text/plain, Size: 598 bytes --]

On Wed, Aug 06, 2014 at 03:52:03PM -0500, Jack Miller wrote:
> 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.

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

[-- Attachment #2: Type: application/pgp-signature, Size: 819 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2014-08-08  9:18 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-08-06 20:52 Embedded NUL (again) Jack Miller
     [not found] ` <1407358323-14044-1-git-send-email-jack-jZyo8ZIaZD9AfugRpC6u6w@public.gmane.org>
2014-08-06 20:52   ` [PATCH] Properly handle embedded nul delimited string lists Jack Miller
     [not found]     ` <1407358323-14044-2-git-send-email-jack-jZyo8ZIaZD9AfugRpC6u6w@public.gmane.org>
2014-08-08  9:18       ` David Gibson
  -- strict thread matches above, loose matches on Subject: below --
2014-08-06 19:31 Embedded NUL (again) Jack Miller
     [not found] ` <1407353512-12182-1-git-send-email-jack-jZyo8ZIaZD9AfugRpC6u6w@public.gmane.org>
2014-08-06 19:31   ` [PATCH] Properly handle embedded nul delimited string lists Jack Miller

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).