Skip to contentSkip to conversation

env: don't add an empty key to the env hashtable

PATCH New Lucian Cojocar 3 participants 6 messages Apr 27, 2013 – May 10, 2013 Library code

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 env: don't add an empty key to the env hashtable

If the environment contains an entry like "=value" "\0" we should skip this key/value. Otherwise, U-Boot will enter in an infinite loop.

---
 lib/hashtable.c |    4 ++++
 1 file changed, 4 insertions(+)
lib/hashtable.c +4 -0
index 07ebfb2..8f5a6f8 100644
@@ -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;
Signature · 1 line
1.7.9.5
#1 lore raw

PATCH 1/1 env: don't add an empty key to the env hashtable

Dear Lucian Cojocar,

Quoted 13 lines · In message <[email protected]> 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.

---
 lib/hashtable.c |    4 ++++
 1 file changed, 4 insertions(+)
lib/hashtable.c +0 -0
index 07ebfb2..8f5a6f8 100644

lib/hashtable.c int himport_r(struct hsearch_data *htab, · line 875

Quoted 6 lines
lib/hashtable.c +3 -0
@@ -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

Signature · 4 lines
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
You cannot propel yourself forward by patting yourself on the back.
#2 lore raw

PATCH 1/1 env: don't add an empty key to the env hashtable

Quoted 19 lines · Wolfgang Denk

Dear Lucian Cojocar,

Quoted 16 lines · In message <[email protected]> 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.

---
  lib/hashtable.c |    4 ++++
  1 file changed, 4 insertions(+)
lib/hashtable.c +0 -0
index 07ebfb2..8f5a6f8 100644
@@ -870,6 +870,10 @@ int himport_r(struct hsearch_data *htab,
  		*sp++ = '\0';	/* terminate value */
  		++dp;
 
Quoted 9 lines

lib/hashtable.c int himport_r(struct hsearch_data *htab, · line 875

Quoted 3 lines
lib/hashtable.c +3 -0
+		/* 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.

Quoted 3 lines

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

#3 lore raw

PATCH 1/1 env: don't add an empty key to the env hashtable

Dear Lucian Cojocar,

Quoted 8 lines · In message <[email protected]> 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

Signature · 6 lines
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
We have found all life forms in the galaxy are  capable  of  superior
development.
	-- Kirk, "The Gamesters of Triskelion", stardate 3211.7
#4 lore raw

PATCH v2 1/1 env: throw an error when an empty key is used

If the environment contains an entry like "=value" "\0" we should throw an error when parsing the environment. Otherwise, U-Boot will enter in an infinite loop.

---
Changes for v2:
- Throw an error instead of silently skip the empty key

 lib/hashtable.c |    6 ++++++
 1 file changed, 6 insertions(+)
lib/hashtable.c +6 -0
index 07ebfb2..779580b 100644
@@ -870,6 +870,12 @@ int himport_r(struct hsearch_data *htab,
 		*sp++ = '\0';	/* terminate value */
 		++dp;
 
+		if (*name == 0) {
+			debug("INSERT: unable to use an empty key\n");
+			__set_errno(EINVAL);
+			return 0;
+		}
+
 		/* Skip variables which are not supposed to be processed */
 		if (!drop_var_from_set(name, nvars, localvars))
 			continue;
Signature · 1 line
1.7.9.5
#5 lore raw

PATCH v2 1/1 env: throw an error when an empty key is used

Quoted 5 lines · Lucian Cojocar

If the environment contains an entry like "=value" "\0" we should throw an error when parsing the environment. Otherwise, U-Boot will enter in an infinite loop.

Applied to u-boot/master, thanks!

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 836 bytes
Desc: Digital signature
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20130510/0d21b8ac/attachment.pgp>