From: Karel Zak Date: Wed, 7 May 2025 10:52:47 +0000 (+0200) Subject: setpriv: protect COLORTERM and NO_COLOR env. variables X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=71f6d70af5ec22f0a59f556373561215d989e0d0;p=thirdparty%2Futil-linux.git setpriv: protect COLORTERM and NO_COLOR env. variables The patch also replaces set/get env with ul_env_list to protect variables. Fixes: https://github.com/util-linux/util-linux/issues/3463 Signed-off-by: Karel Zak --- diff --git a/sys-utils/setpriv.c b/sys-utils/setpriv.c index 433db6031..203f128c1 100644 --- a/sys-utils/setpriv.c +++ b/sys-utils/setpriv.c @@ -721,18 +721,20 @@ static void do_seccomp_filter(const char *file) static void do_reset_environ(struct passwd *pw) { - char *term = getenv("TERM"); + struct ul_env_list *saved; + + saved = env_list_add_getenv(NULL, "TERM", NULL); + saved = env_list_add_getenv(saved, "COLORTERM", NULL); + saved = env_list_add_getenv(saved, "NO_COLOR", NULL); - if (term) - term = xstrdup(term); #ifdef HAVE_CLEARENV clearenv(); #else environ = NULL; #endif - if (term) { - xsetenv("TERM", term, 1); - free(term); + if (saved) { + env_list_setenv(saved, 1); + env_list_free(saved); } if (pw->pw_shell && *pw->pw_shell)