From: Simon Goldschmidt <sgoldschmidt@de.pepperl-fuchs.com>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH] cmd: nvedit: env_get_f must check for env_get_char error codes
Date: Thu, 1 Feb 2018 10:16:46 +0100 [thread overview]
Message-ID: <86985599-0df7-a690-b027-1ce740235bd8@de.pepperl-fuchs.com> (raw)
In-Reply-To: <VI1PR04MB2078998522CF728ED7B0FD429AFB0@VI1PR04MB2078.eurprd04.prod.outlook.com>
On 01.02.2018 00:00, York Sun wrote:
> On 01/30/2018 10:57 PM, Simon Goldschmidt wrote:
>> env_get_f calls env_get_char to load single characters from the
>> environment. However, the return value of env_get_char was not
>> checked for errors. Now if the env driver does not support the
>> .get_char call, env_get_f did not notice this and looped over the
>> whole size of the environment, calling env_get_char over 8000
>> times with the default settings, just to return an error in the
>> end.
>>
>> Fix this by checking if env_get_char returns < 0.
>>
>> Signed-off-by: Simon Goldschmidt <sgoldschmidt@de.pepperl-fuchs.com>
>> ---
>>
>> cmd/nvedit.c | 11 ++++++++---
>> 1 file changed, 8 insertions(+), 3 deletions(-)
>>
>> diff --git a/cmd/nvedit.c b/cmd/nvedit.c
>> index a690d743cd..4cb25b8248 100644
>> --- a/cmd/nvedit.c
>> +++ b/cmd/nvedit.c
>> @@ -650,12 +650,14 @@ char *env_get(const char *name)
>> */
>> int env_get_f(const char *name, char *buf, unsigned len)
>> {
>> - int i, nxt;
>> + int i, nxt, c;
>>
>> for (i = 0; env_get_char(i) != '\0'; i = nxt + 1) {
>> int val, n;
>>
>> - for (nxt = i; env_get_char(nxt) != '\0'; ++nxt) {
>> + for (nxt = i; (c = env_get_char(nxt)) != '\0'; ++nxt) {
>> + if (c < 0)
>> + return c;
>> if (nxt >= CONFIG_ENV_SIZE)
>> return -1;
>> }
>> @@ -666,7 +668,10 @@ int env_get_f(const char *name, char *buf, unsigned len)
>>
>> /* found; copy out */
>> for (n = 0; n < len; ++n, ++buf) {
>> - *buf = env_get_char(val++);
>> + c = env_get_char(val++);
>> + if (c < 0)
>> + return c;
>> + *buf = c;
>> if (*buf == '\0')
>> return n;
>> }
>>
> Simon,
>
> This patch looks correct. But it doesn't fix NOR flash. Do you have plan
> to add .get_char function to other drivers? Without that function, we
> cannot get env variables before relocation.
Ehrm, sorry I don't plan to do that, no: my target seems to run fine
without this.
Given that only the eeprom and nvram env drivers support the get_char
method, I don't know if this is widely used at all. Maybe a better
fallback would be to just remove that get_char code path totally and
always load from the internal (default) environment until the full
environment is available (after relocation).
After all, the environment variables loaded via get_char are not CRC
checked at all. To me, this is another indication that this code is not
really useful and should probably be removed.
Maxime and others, what do you think?
Simon
next prev parent reply other threads:[~2018-02-01 9:16 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-01-31 6:56 [U-Boot] [PATCH] cmd: nvedit: env_get_f must check for env_get_char error codes Simon Goldschmidt
2018-01-31 8:39 ` Maxime Ripard
2018-01-31 23:00 ` York Sun
2018-02-01 9:16 ` Simon Goldschmidt [this message]
2018-02-02 18:51 ` Maxime Ripard
2018-02-02 20:04 ` York Sun
2018-02-05 13:43 ` Maxime Ripard
2018-02-05 16:30 ` York Sun
2018-02-07 8:31 ` Maxime Ripard
2018-02-01 13:09 ` [U-Boot] " Tom Rini
2018-02-03 10:27 [U-Boot] [PATCH] " Goldschmidt Simon
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=86985599-0df7-a690-b027-1ce740235bd8@de.pepperl-fuchs.com \
--to=sgoldschmidt@de.pepperl-fuchs.com \
--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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.