]> git.dujemihanovic.xyz Git - u-boot.git/commitdiff
env: Early return from env_get_f() on NULL name
authorMarek Behún <marek.behun@nic.cz>
Sun, 17 Oct 2021 15:36:34 +0000 (17:36 +0200)
committerSimon Glass <sjg@chromium.org>
Thu, 21 Oct 2021 18:50:48 +0000 (12:50 -0600)
Test non-NULL name immediately, not in env_match().

Signed-off-by: Marek Behún <marek.behun@nic.cz>
Reviewed-by: Simon Glass <sjg@chromium.org>
cmd/nvedit.c

index 8d53579d92e73529d5ac3e29d3b4b55c597ba244..063cc762823f966090792bff4069ccaa0126bcfb 100644 (file)
@@ -708,9 +708,6 @@ char *from_env(const char *envvar)
 
 static const char *env_match(const char *p, const char *s1)
 {
-       if (s1 == NULL || *s1 == '\0')
-               return NULL;
-
        while (*s1 == *p++)
                if (*s1++ == '=')
                        return p;
@@ -728,6 +725,9 @@ int env_get_f(const char *name, char *buf, unsigned len)
 {
        const char *env, *p, *end;
 
+       if (name == NULL || *name == '\0')
+               return -1;
+
        if (gd->env_valid == ENV_INVALID)
                env = (const char *)default_environment;
        else