From 6b6e3eeba9f96b5d908a9b46b7bb25e76109a0c7 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Marek=20Beh=C3=BAn?= Date: Sun, 17 Oct 2021 17:36:34 +0200 Subject: [PATCH] env: Early return from env_get_f() on NULL name MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Test non-NULL name immediately, not in env_match(). Signed-off-by: Marek Behún Reviewed-by: Simon Glass --- cmd/nvedit.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/cmd/nvedit.c b/cmd/nvedit.c index 8d53579d92..063cc76282 100644 --- a/cmd/nvedit.c +++ b/cmd/nvedit.c @@ -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 -- 2.39.5