public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
From: Ken MacLeod <ken@bitsko.slc.ut.us>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH v2] cmd_fdt.c: fix parse of byte streams and strings
Date: Fri, 11 Sep 2009 15:16:18 -0500	[thread overview]
Message-ID: <m3sketfd9p.fsf@bitsko.slc.ut.us> (raw)

Commit 4abd844d8e extended the fdt command parser to handle property
strings which are split across multiple arguments but it was broken for
byte streams and strings.

Byte stream parsing:

 * Fixes where it would terminate early or go into an endless loop.

 * Fixes a 0x00 being inserted into the data if there is a space after
   '[' or a separate argument.

 * Fixes dereferencing the argument pointer after the last argument.

 * Checks for bad characters.

String parsing:

 * Treat multiple arguments as a string list.  This fixes an issue where
   only the last argument was stored.

Signed-off-by: Ken MacLeod <ken@bitsko.slc.ut.us>
---

The previous version of this patch 1) only fixed the first byte stream
issue above and 2) concatenated the string arguments rather than
creating a list (pointed out by Scott Wood).

 common/cmd_fdt.c |   23 +++++++++++++++--------
 1 files changed, 15 insertions(+), 8 deletions(-)

diff --git a/common/cmd_fdt.c b/common/cmd_fdt.c
index 8683772..919a0bf 100644
--- a/common/cmd_fdt.c
+++ b/common/cmd_fdt.c
@@ -574,14 +574,18 @@ static int fdt_parse_prop(char **newval, int count, char *data, int *len)
 		 * Byte stream.  Convert the values.
 		 */
 		newp++;
-		while ((*newp != ']') && (stridx < count)) {
-			tmp = simple_strtoul(newp, &newp, 16);
-			*data++ = tmp & 0xFF;
-			*len    = *len + 1;
+		while ((stridx < count) && (*newp != ']')) {
 			while (*newp == ' ')
 				newp++;
-			if (*newp != '\0')
+			if (*newp == '\0') {
 				newp = newval[++stridx];
+				continue;
+			}
+			if (!isxdigit(*newp))
+				break;
+			tmp = simple_strtoul(newp, &newp, 16);
+			*data++ = tmp & 0xFF;
+			*len    = *len + 1;
 		}
 		if (*newp != ']') {
 			printf("Unexpected character '%c'\n", *newp);
@@ -589,12 +593,15 @@ static int fdt_parse_prop(char **newval, int count, char *data, int *len)
 		}
 	} else {
 		/*
-		 * Assume it is a string.  Copy it into our data area for
-		 * convenience (including the terminating '\0').
+		 * Assume it is one or more strings.  Copy it into our
+		 * data area for convenience (including the
+		 * terminating '\0's).
 		 */
 		while (stridx < count) {
-			*len = strlen(newp) + 1;
+			size_t length = strlen(newp) + 1;
 			strcpy(data, newp);
+			data += length;
+			*len += length;
 			newp = newval[++stridx];
 		}
 	}
-- 
1.5.4.7

             reply	other threads:[~2009-09-11 20:16 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-09-11 20:16 Ken MacLeod [this message]
2009-09-11 20:21 ` [U-Boot] [PATCH v2] cmd_fdt.c: fix parse of byte streams and strings Jerry Van Baren

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=m3sketfd9p.fsf@bitsko.slc.ut.us \
    --to=ken@bitsko.slc.ut.us \
    --cc=u-boot@lists.denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox