* [U-Boot] [PATCH 1/2] hwconfig: Fix stop characters parsing for subkeys
@ 2010-06-18 11:08 Anton Vorontsov
2010-06-29 20:24 ` Wolfgang Denk
0 siblings, 1 reply; 2+ messages in thread
From: Anton Vorontsov @ 2010-06-18 11:08 UTC (permalink / raw)
To: u-boot
For the following hwconfig string:
key1:subkey1=value1,subkey2=value2;key2:value3
The subkey2 cannot be extracted correctly. The parsing code looks
for comma as a stopch, but there may be two kind of stop characters:
a comma and a semicolon.
Currently the code would return "value2;key2:value3", while just
"value2" is the correct answer.
This patch fixes the issue by making the code aware of multiple
stop characters.
For old U-Boots, the issue can be workarounded by placing a comma
before a semicolon, i.e.:
hwconfig=key1:subkey1=value1,subkey2=value2,;key2:value3
Reported-by: York Sun <yorksun@freescale.com>
Signed-off-by: Anton Vorontsov <avorontsov@mvista.com>
---
common/hwconfig.c | 19 ++++++++++---------
1 files changed, 10 insertions(+), 9 deletions(-)
diff --git a/common/hwconfig.c b/common/hwconfig.c
index e5c60ba..85a69da 100644
--- a/common/hwconfig.c
+++ b/common/hwconfig.c
@@ -19,7 +19,7 @@
#include <linux/string.h>
static const char *hwconfig_parse(const char *opts, size_t maxlen,
- const char *opt, char stopch, char eqch,
+ const char *opt, char *stopchs, char eqch,
size_t *arglen)
{
size_t optlen = strlen(opt);
@@ -33,8 +33,9 @@ next:
if (end - start > maxlen)
return NULL;
- if (str && (str == opts || str[-1] == stopch) &&
- (*end == stopch || *end == eqch || *end == '\0')) {
+ if (str && (str == opts || strpbrk(str - 1, stopchs) == str - 1) &&
+ (strpbrk(end, stopchs) == end || *end == eqch ||
+ *end == '\0')) {
const char *arg_end;
if (!arglen)
@@ -43,7 +44,7 @@ next:
if (*end != eqch)
return NULL;
- arg_end = strchr(str, stopch);
+ arg_end = strpbrk(str, stopchs);
if (!arg_end)
*arglen = min(maxlen, strlen(str)) - optlen - 1;
else
@@ -66,15 +67,15 @@ static const char *__hwconfig(const char *opt, size_t *arglen)
if (env_hwconfig)
return hwconfig_parse(env_hwconfig, strlen(env_hwconfig),
- opt, ';', ':', arglen);
+ opt, ";", ':', arglen);
if (board_hwconfig)
return hwconfig_parse(board_hwconfig, strlen(board_hwconfig),
- opt, ';', ':', arglen);
+ opt, ";", ':', arglen);
if (cpu_hwconfig)
return hwconfig_parse(cpu_hwconfig, strlen(cpu_hwconfig),
- opt, ';', ':', arglen);
+ opt, ";", ':', arglen);
return NULL;
}
@@ -164,7 +165,7 @@ int hwconfig_sub(const char *opt, const char *subopt)
arg = __hwconfig(opt, &arglen);
if (!arg)
return 0;
- return !!hwconfig_parse(arg, arglen, subopt, ',', '=', NULL);
+ return !!hwconfig_parse(arg, arglen, subopt, ",;", '=', NULL);
}
/*
@@ -185,7 +186,7 @@ const char *hwconfig_subarg(const char *opt, const char *subopt,
arg = __hwconfig(opt, &arglen);
if (!arg)
return NULL;
- return hwconfig_parse(arg, arglen, subopt, ',', '=', subarglen);
+ return hwconfig_parse(arg, arglen, subopt, ",;", '=', subarglen);
}
/*
--
1.7.0.5
^ permalink raw reply related [flat|nested] 2+ messages in thread
* [U-Boot] [PATCH 1/2] hwconfig: Fix stop characters parsing for subkeys
2010-06-18 11:08 [U-Boot] [PATCH 1/2] hwconfig: Fix stop characters parsing for subkeys Anton Vorontsov
@ 2010-06-29 20:24 ` Wolfgang Denk
0 siblings, 0 replies; 2+ messages in thread
From: Wolfgang Denk @ 2010-06-29 20:24 UTC (permalink / raw)
To: u-boot
Dear Anton Vorontsov,
In message <20100618110812.GA26595@oksana.dev.rtsoft.ru> you wrote:
> For the following hwconfig string:
>
> key1:subkey1=value1,subkey2=value2;key2:value3
>
> The subkey2 cannot be extracted correctly. The parsing code looks
> for comma as a stopch, but there may be two kind of stop characters:
> a comma and a semicolon.
>
> Currently the code would return "value2;key2:value3", while just
> "value2" is the correct answer.
>
> This patch fixes the issue by making the code aware of multiple
> stop characters.
>
> For old U-Boots, the issue can be workarounded by placing a comma
> before a semicolon, i.e.:
>
> hwconfig=key1:subkey1=value1,subkey2=value2,;key2:value3
>
> Reported-by: York Sun <yorksun@freescale.com>
> Signed-off-by: Anton Vorontsov <avorontsov@mvista.com>
> ---
> common/hwconfig.c | 19 ++++++++++---------
> 1 files changed, 10 insertions(+), 9 deletions(-)
Applied to "next" branch.
Best regards,
Wolfgang Denk
--
DENX Software Engineering GmbH, MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de
A supercomputer is a machine that runs an endless loop in 2 seconds.
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2010-06-29 20:24 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-06-18 11:08 [U-Boot] [PATCH 1/2] hwconfig: Fix stop characters parsing for subkeys Anton Vorontsov
2010-06-29 20:24 ` Wolfgang Denk
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox