Patchwork [U-Boot] env: don't add an empty key to the env hashtable

login
register
mail settings
Submitter Lucian Cojocar
Date April 27, 2013, 9:56 p.m.
Message ID <1367099787-25602-1-git-send-email-cojocar@gmail.com>
Download mbox | patch
Permalink /patch/240209/
State Superseded
Delegated to: Tom Rini
Headers show

Comments

Lucian Cojocar - April 27, 2013, 9:56 p.m.
If the environment contains an entry like "=value" "\0" we should skip
this key/value. Otherwise, U-Boot will enter in an infinite loop.

Signed-off-by: Lucian Cojocar <cojocar@gmail.com>
---
 lib/hashtable.c |    4 ++++
 1 file changed, 4 insertions(+)
Wolfgang Denk - April 27, 2013, 10:35 p.m.
Dear Lucian Cojocar,

In message <1367099787-25602-1-git-send-email-cojocar@gmail.com> you wrote:
> If the environment contains an entry like "=value" "\0" we should skip
> this key/value. Otherwise, U-Boot will enter in an infinite loop.
> 
> Signed-off-by: Lucian Cojocar <cojocar@gmail.com>
> ---
>  lib/hashtable.c |    4 ++++
>  1 file changed, 4 insertions(+)
> 
> diff --git a/lib/hashtable.c b/lib/hashtable.c
> index 07ebfb2..8f5a6f8 100644
> --- a/lib/hashtable.c
> +++ b/lib/hashtable.c
> @@ -870,6 +870,10 @@ int himport_r(struct hsearch_data *htab,
>  		*sp++ = '\0';	/* terminate value */
>  		++dp;
>  
> +		/* skip this entry if the name is empty */
> +		if (*name == 0)
> +			continue;

NAK.   This would be a serious error, and silently ignoring this is
downright wrong.

If such a situation should ever happen, it must cause a fatal error.

Could you please explain which exact problem you are trying to fix? 
I have to admit that I cannot think of a usage szenario that would
lead to such an error.

Best regards,

Wolfgang Denk
Lucian Cojocar - April 27, 2013, 11:08 p.m.
On 04/28/2013 12:35 AM, Wolfgang Denk wrote:
> Dear Lucian Cojocar,
>
> In message <1367099787-25602-1-git-send-email-cojocar@gmail.com> you wrote:
>> If the environment contains an entry like "=value" "\0" we should skip
>> this key/value. Otherwise, U-Boot will enter in an infinite loop.
>>
>> Signed-off-by: Lucian Cojocar <cojocar@gmail.com>
>> ---
>>   lib/hashtable.c |    4 ++++
>>   1 file changed, 4 insertions(+)
>>
>> diff --git a/lib/hashtable.c b/lib/hashtable.c
>> index 07ebfb2..8f5a6f8 100644
>> --- a/lib/hashtable.c
>> +++ b/lib/hashtable.c
>> @@ -870,6 +870,10 @@ int himport_r(struct hsearch_data *htab,
>>   		*sp++ = '\0';	/* terminate value */
>>   		++dp;
>>
>> +		/* skip this entry if the name is empty */
>> +		if (*name == 0)
>> +			continue;
>
> NAK.   This would be a serious error, and silently ignoring this is
> downright wrong.
>
> If such a situation should ever happen, it must cause a fatal error.
>

I agree.

> Could you please explain which exact problem you are trying to fix?
> I have to admit that I cannot think of a usage szenario that would
> lead to such an error.

I had an error (typo) in my predefined environment. Basically I had this:

#define CONFIG_EXTRA_ENV_SETTINGS \
	"key" "\0" "=value" "\0"

It would be nice if U-Boot told me that there was something wrong with 
my environment rather than just hang.

Thanks,
Lucian
Wolfgang Denk - April 28, 2013, 9:06 a.m.
Dear Lucian Cojocar,

In message <517C5A5A.2010106@gmail.com> you wrote:
>
> I had an error (typo) in my predefined environment. Basically I had this:
> 
> #define CONFIG_EXTRA_ENV_SETTINGS \
> 	"key" "\0" "=value" "\0"
> 
> It would be nice if U-Boot told me that there was something wrong with 
> my environment rather than just hang.

Agreed - it should throw an error.

Best regards,

Wolfgang Denk

Patch

diff --git a/lib/hashtable.c b/lib/hashtable.c
index 07ebfb2..8f5a6f8 100644
--- a/lib/hashtable.c
+++ b/lib/hashtable.c
@@ -870,6 +870,10 @@  int himport_r(struct hsearch_data *htab,
 		*sp++ = '\0';	/* terminate value */
 		++dp;
 
+		/* skip this entry if the name is empty */
+		if (*name == 0)
+			continue;
+
 		/* Skip variables which are not supposed to be processed */
 		if (!drop_var_from_set(name, nvars, localvars))
 			continue;