From patchwork Fri Oct 5 10:46:10 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: [U-Boot] env: fix crash using default -f -a X-Patchwork-Submitter: Gerlando Falauto X-Patchwork-Id: 189456 X-Patchwork-Delegate: trini@ti.com Message-Id: <1349433970-16689-1-git-send-email-gerlando.falauto@keymile.com> To: sbabic@denx.de, u-boot@lists.denx.de Cc: trini@ti.com, Gerlando Falauto Date: Fri, 5 Oct 2012 12:46:10 +0200 From: Gerlando Falauto List-Id: U-Boot discussion env default -a -f calls env_check_apply on all existing environment variables with a NULL value for "newval" as a way of cleaning up. This causes string manipulation functions to crash on most architectures. So replace a NULL argument with an empty string. Reported-By: Stefano Babic Signed-off-by: Gerlando Falauto Tested-by: Stefano Babic --- common/cmd_nvedit.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/common/cmd_nvedit.c b/common/cmd_nvedit.c index 3474bc6..c38b475 100644 --- a/common/cmd_nvedit.c +++ b/common/cmd_nvedit.c @@ -213,6 +213,9 @@ int env_check_apply(const char *name, const char *oldval, { int console = -1; + /* Default value for NULL to protect string-manipulating functions */ + newval = newval ? : ""; + /* Check for console redirection */ if (strcmp(name, "stdin") == 0) console = stdin;