Patchwork [U-Boot,v2,5/5] env: Check for NULL pointer in envmatch()

login
register
mail settings
Submitter Joe Hershberger
Date Oct. 3, 2012, 7:38 p.m.
Message ID <1349293130-5715-6-git-send-email-joe.hershberger@ni.com>
Download mbox | patch
Permalink /patch/188916/
State Accepted
Delegated to: Tom Rini
Headers show

Comments

Joe Hershberger - Oct. 3, 2012, 7:38 p.m.
If the pointer passed into envmatch() is NULL, return -1 instead of
crashing.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
---

 common/cmd_nvedit.c | 3 +++
 tools/env/fw_env.c  | 2 ++
 2 files changed, 5 insertions(+)

Patch

diff --git a/common/cmd_nvedit.c b/common/cmd_nvedit.c
index 3474bc6..5a28dee 100644
--- a/common/cmd_nvedit.c
+++ b/common/cmd_nvedit.c
@@ -646,6 +646,9 @@  U_BOOT_CMD(
  */
 int envmatch(uchar *s1, int i2)
 {
+	if (s1 == NULL)
+		return -1;
+
 	while (*s1 == env_get_char(i2++))
 		if (*s1++ == '=')
 			return i2;
diff --git a/tools/env/fw_env.c b/tools/env/fw_env.c
index f883804..ed56ba0 100644
--- a/tools/env/fw_env.c
+++ b/tools/env/fw_env.c
@@ -1060,6 +1060,8 @@  exit:
 
 static char *envmatch (char * s1, char * s2)
 {
+	if (s1 == NULL || s2 == NULL)
+		return NULL;
 
 	while (*s1 == *s2++)
 		if (*s1++ == '=')