From: Karel Zak Date: Thu, 7 Nov 2024 10:31:07 +0000 (+0100) Subject: lib/env: fix env_list_setenv() for strings without '=' X-Git-Tag: v2.40.3~63 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=10a7ce1a048f7f5d9b610e37c271e0cf42cd3791;p=thirdparty%2Futil-linux.git lib/env: fix env_list_setenv() for strings without '=' If there is no '=' in the string, the function will not move to the next list item and will loop indefinitely. Fixes: https://github.com/util-linux/util-linux/issues/3270 Signed-off-by: Karel Zak --- diff --git a/lib/env.c b/lib/env.c index 2bdfe5697..24ae90d00 100644 --- a/lib/env.c +++ b/lib/env.c @@ -118,13 +118,13 @@ int env_list_setenv(struct ul_env_list *ls) int rc = 0; while (ls && rc == 0) { - if (ls->env) { + if (ls->env && *ls->env) { char *val = strchr(ls->env, '='); - if (!val) - continue; - *val = '\0'; - rc = setenv(ls->env, val + 1, 0); - *val = '='; + if (val) { + *val = '\0'; + rc = setenv(ls->env, val + 1, 0); + *val = '='; + } } ls = ls->next; }