From: Todd C. Miller Date: Thu, 11 Nov 2004 16:20:59 +0000 (+0000) Subject: strip exported bash functions from the environment. X-Git-Tag: SUDO_1_7_0~846 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=482526bde130a6f892cab0bbbd5357266ea93a81;p=sudo strip exported bash functions from the environment. --- diff --git a/env.c b/env.c index 9a0b4a204..7f4389f35 100644 --- a/env.c +++ b/env.c @@ -323,6 +323,13 @@ rebuild_env(envp, sudo_mode, noexec) /* Pull in vars we want to keep from the old environment. */ for (ep = envp; *ep; ep++) { keepit = 0; + + /* Skip variables with values beginning with () (bash functions) */ + if ((cp = strchr(*ep, '=')) != NULL) { + if (strncmp(cp, "=() ", 3) == 0) + continue; + } + for (cur = def_env_keep; cur; cur = cur->next) { len = strlen(cur->value); /* Deal with '*' wildcard */ @@ -405,6 +412,12 @@ rebuild_env(envp, sudo_mode, noexec) for (ep = envp; *ep; ep++) { okvar = 1; + /* Skip variables with values beginning with () (bash functions) */ + if ((cp = strchr(*ep, '=')) != NULL) { + if (strncmp(cp, "=() ", 3) == 0) + continue; + } + /* Skip anything listed in env_delete. */ for (cur = def_env_delete; cur && okvar; cur = cur->next) { len = strlen(cur->value);