[U-Boot] [PATCH v1] env: fix crash using default -f -a

Stefano Babic sbabic at denx.de
Fri Oct 5 12:41:40 CEST 2012


On 05/10/2012 12:29, Gerlando Falauto wrote:
> Hi Stefano,
> 

Hi Gerlando,

> thanks for reporting and providing a fix for this.
> I'm very sorry for introducing this problem and for the late response.
> 
> Please see my comments below.
> 
> [As a side node, I couldn't really reproduce the issue neither on
> PowerPC nor on ARM (though simple_strtoul should legitimately crash) as
> apparently accessing NULL locations doesn't really bother our
> architectures...]

Right. For PowerPC, Address 0 is a valid address in memory and the
system does not crash. However, I tested on a TI's ARM and address zero
is not valid.

> 
> On 10/04/2012 07:30 PM, Stefano Babic wrote:
>> newval pointer is not checked before its usage,
>> inside env_check_apply().
>>
>> Signed-off-by: Stefano Babic<sbabic at denx.de>
>> CC: gerlando.falauto at keymile.com
>> ---
>>   common/cmd_nvedit.c |    6 +++---
>>   1 file changed, 3 insertions(+), 3 deletions(-)
>>
>> diff --git a/common/cmd_nvedit.c b/common/cmd_nvedit.c
>> index 3474bc6..8144c85 100644
>> --- a/common/cmd_nvedit.c
>> +++ b/common/cmd_nvedit.c
>> @@ -272,7 +272,7 @@ int env_check_apply(const char *name, const char
>> *oldval,
>>           /*
>>            * Switch to new baudrate if new baudrate is supported
>>            */
>> -        if (strcmp(name, "baudrate") == 0) {
>> +        if ((strcmp(name, "baudrate") == 0)&&  (newval != NULL)) {
> 
> You're right in that the problem here is due to the function explicitly
> being called with a NULL value.
> My idea was to have "env default" perform some sort of cleanup before
> assigning the actual values from the default environment (if any).

I have seen, I have not fully understood. My idea is that, if someone
want to restore the environment to the default values, no actions should
be taken, else the "default" values cannot be really restored.

> So by adding these extra checks you're subtly canceling those efforts.

That is correct, but in any case a check for a NULL pointer should be
done before accessing to the pointer, independently what we want to do
with it.

> So I would rather provide a default value to prevent the crashes,
> instead of skipping settings altogether. Posting a patch in a few minutes.

Ok, I will review it. In any case, we need a fix for the coming release.

> 
> Whether it's legitimate to perform these "cleanups", well that's of
> course open for discussion.

Indeed.

> But I believe it doesn't make much sense to call a function and pass an
> argument which is sort of guaranteed to have no effect whatsoever.

Right. It is the same as calling the function with do_apply=0.

> 
>>               int baudrate = simple_strtoul(newval, NULL, 10);
>>               int i;
>>               for (i = 0; i<  N_BAUDRATES; ++i) {
>> @@ -308,12 +308,12 @@ int env_check_apply(const char *name, const char
>> *oldval,
>>        * Some variables should be updated when the corresponding
>>        * entry in the environment is changed
>>        */
>> -    if (strcmp(name, "loadaddr") == 0) {
>> +    if ((strcmp(name, "loadaddr") == 0)&&  (newval != NULL)) {
>>           load_addr = simple_strtoul(newval, NULL, 16);
>>           return 0;
>>       }
>>   #if defined(CONFIG_CMD_NET)
>> -    else if (strcmp(name, "bootfile") == 0) {
>> +    else if ((strcmp(name, "bootfile") == 0)&&  (newval != NULL)) {
>>           copy_filename(BootFile, newval, sizeof(BootFile));
>>           return 0;
>>       }
>

Best regards,
Stefano


-- 
=====================================================================
DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: +49-8142-66989-53 Fax: +49-8142-66989-80 Email: sbabic at denx.de
=====================================================================


More information about the U-Boot mailing list