[U-Boot] [PATCH 1/2] tools/env: Fix variable delete operation

Joe Hershberger joe.hershberger at ni.com
Tue Oct 16 03:29:24 CEST 2012


Fix crash introduced by a073d63a36524453a817ab029fad5b188f46127e
when attempting to delete a variable.

Signed-off-by: Joe Hershberger <joe.hershberger at ni.com>
---
 tools/env/fw_env.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/tools/env/fw_env.c b/tools/env/fw_env.c
index 520ce3f..906ccbf 100644
--- a/tools/env/fw_env.c
+++ b/tools/env/fw_env.c
@@ -493,6 +493,8 @@ int fw_setenv(int argc, char *argv[])
 		char *val = argv[i];
 		size_t val_len = strlen(val);
 
+		if (value)
+			value[len - 1] = ' ';
 		value = realloc(value, len + val_len + 1);
 		if (!value) {
 			fprintf(stderr,
@@ -503,9 +505,8 @@ int fw_setenv(int argc, char *argv[])
 
 		memcpy(value + len, val, val_len);
 		len += val_len;
-		value[len++] = ' ';
+		value[len++] = '\0';
 	}
-	value[len - 1] = '\0';
 
 	fw_env_write(name, value);
 
-- 
1.7.11.5



More information about the U-Boot mailing list