env: Check for NULL pointer in envmatch()
authorJoe Hershberger <joe.hershberger@ni.com>
Wed, 3 Oct 2012 09:38:50 +0000 (09:38 +0000)
committerTom Rini <trini@ti.com>
Mon, 15 Oct 2012 18:54:05 +0000 (11:54 -0700)
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
tools/env/fw_env.c

index d655ab9684eef9389c798cbc199a451a484e7189..1f9c674260233d6944dd4419596156cd750b2027 100644 (file)
@@ -650,6 +650,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;
index 2c607bf4916bb0c9e865c00270886afdde57b794..520ce3fd89840d81cfcaebde2049272876c8c74d 100644 (file)
@@ -1057,6 +1057,8 @@ exit:
 
 static char *envmatch (char * s1, char * s2)
 {
+       if (s1 == NULL || s2 == NULL)
+               return NULL;
 
        while (*s1 == *s2++)
                if (*s1++ == '=')