Patchwork [U-Boot,v2] env: throw an error when an empty key is used

login
register
mail settings
Submitter Lucian Cojocar
Date April 28, 2013, 9:31 p.m.
Message ID <f62827128a7393cbc034689bbc13e47aea159d70.1367183896.git.cojocar@gmail.com>
Download mbox | patch
Permalink /patch/240308/
State Accepted
Delegated to: Tom Rini
Headers show

Comments

Lucian Cojocar - April 28, 2013, 9:31 p.m.
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.

Signed-off-by: Lucian Cojocar <cojocar@gmail.com>
---
Changes for v2:
    - Throw an error instead of silently skip the empty key

 lib/hashtable.c |    6 ++++++
 1 file changed, 6 insertions(+)
Tom Rini - May 10, 2013, 7:58 p.m.
On Sun, Apr 28, 2013 at 11:31:57AM -0000, Lucian Cojocar wrote:

> 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.
> 
> Signed-off-by: Lucian Cojocar <cojocar@gmail.com>

Applied to u-boot/master, thanks!

Patch

diff --git a/lib/hashtable.c b/lib/hashtable.c
index 07ebfb2..779580b 100644
--- a/lib/hashtable.c
+++ b/lib/hashtable.c
@@ -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;