From mboxrd@z Thu Jan 1 00:00:00 1970 From: Jack Miller Subject: [PATCH 2/2] Properly handle nul delimited string lists Date: Tue, 24 Jun 2014 13:31:52 -0500 Message-ID: <1403634712-3479-2-git-send-email-jack@codezen.org> Return-path: Sender: devicetree-compiler-owner-u79uwXL29TY76Z2rM5mHXA@public.gmane.org List-ID: MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: devicetree-compiler-u79uwXL29TY76Z2rM5mHXA@public.gmane.org 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 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/nul_string_list.dtb b/tests/nul_string_list.dtb new file mode 100644 index 0000000000000000000000000000000000000000..ea2bc3915d8129c849d2cc7b247bc9d1a201256c GIT binary patch literal 127 zcmcb>`|m9S14BI!TL5tZ5NiOjAP@@xF$nMjF-Q&_FhT{GfwVM;U6fj!T2z*52xAz* W7{*|gOhA$oswPD@FEKZ@m;nI8VH4E= literal 0 HcmV?d00001 diff --git a/tests/nul_string_list.dts b/tests/nul_string_list.dts new file mode 100644 index 0000000000000000000000000000000000000000..845a14425fd36db3fac2934d1412dbb2cd8fb3a9 GIT binary patch literal 66 zcmdN-DJj-1Gt{@{;?h^B=He_$Elw>eOHI+uOUz9zR