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>
* 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);
}
} 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];
}
}