diff mbox

[U-Boot] env: fix crash using default -f -a

Message ID 1349433970-16689-1-git-send-email-gerlando.falauto@keymile.com
State Accepted
Delegated to: Tom Rini
Headers show

Commit Message

Gerlando Falauto Oct. 5, 2012, 10:46 a.m. UTC
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 <sbabic@denx.de>
Signed-off-by: Gerlando Falauto <gerlando.falauto@keymile.com>
---
 common/cmd_nvedit.c |    3 +++
 1 file changed, 3 insertions(+)

Comments

Stefano Babic Oct. 5, 2012, 11:50 a.m. UTC | #1
On 05/10/2012 12:46, Gerlando Falauto wrote:
> 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 <sbabic@denx.de>
> Signed-off-by: Gerlando Falauto <gerlando.falauto@keymile.com>
> ---
>  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;
> 

It fixes the issue.

Tested-by: Stefano Babic <sbabic@denx.de>

Best regards,
Stefano
Tom Rini Oct. 5, 2012, 10:26 p.m. UTC | #2
On Fri, Oct 05, 2012 at 12:46:10PM +0200, Gerlando Falauto wrote:

> 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 <sbabic@denx.de>
> Signed-off-by: Gerlando Falauto <gerlando.falauto@keymile.com>

Applied to u-boot/master, thanks!
diff mbox

Patch

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;