]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
lib/env: fix env_list_setenv() for strings without '='
authorKarel Zak <kzak@redhat.com>
Thu, 7 Nov 2024 10:31:07 +0000 (11:31 +0100)
committerKarel Zak <kzak@redhat.com>
Thu, 7 Nov 2024 10:31:07 +0000 (11:31 +0100)
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 <kzak@redhat.com>
lib/env.c

index 2bdfe5697e900fdf0273ee83125ff60e2cb39918..24ae90d0051cdf01cb2648a5fa36531cd68d4142 100644 (file)
--- 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;
        }