[PATCH 2/5] env: Fix env_get() when returning empty string using env_get_f()

Simon Glass sjg at chromium.org
Fri Oct 29 05:17:38 CEST 2021


Hi Marek,

On Wed, 27 Oct 2021 at 21:28, Marek Behún <kabel at kernel.org> wrote:
>
> From: Marek Behún <marek.behun at nic.cz>
>
> The env_get_f() function returns -1 on failure. Returning 0 means that
> the variable exists, and is empty string.
>
> Signed-off-by: Marek Behún <marek.behun at nic.cz>
> ---
>  env/common.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)

Reviewed-by: Simon Glass <sjg at chromium.org>

But it isn't normally possible to set an env var to an empty string.
How does this happen?

>
> diff --git a/env/common.c b/env/common.c
> index 2aa23545ba..757c5f9ecd 100644
> --- a/env/common.c
> +++ b/env/common.c
> @@ -125,7 +125,7 @@ char *env_get(const char *name)
>         }
>
>         /* restricted capabilities before import */
> -       if (env_get_f(name, (char *)(gd->env_buf), sizeof(gd->env_buf)) > 0)
> +       if (env_get_f(name, (char *)(gd->env_buf), sizeof(gd->env_buf)) >= 0)
>                 return (char *)(gd->env_buf);
>
>         return NULL;
> --
> 2.32.0
>

Regards,
Simon


More information about the U-Boot mailing list