From 13f35bd5b1156609977b3cdaaccae3bf1e2da7dd Mon Sep 17 00:00:00 2001 From: Allan Odgaard Date: Fri, 21 Sep 2012 17:48:20 +0200 Subject: [PATCH] Whitelist rather than blacklist inherited variables Initially the environment was clean but it was found that some variables should be inherited, e.g. SSH_AUTH_SOCK. Therefor a blacklist was introduced, but it seems futile trying to keep it updated with all the variables that may affect the behavior of commands executed from within TextMate, therefor we now use a whitelist. Probably the whitelist should be user configurable as launchd uses environment variables to communicate dynamically allocated sockets (like SSH_AUTH_SOCK, but there are also some Apple-prefixed variables pointing to named sockets). Issue #238. --- Frameworks/io/src/environment.cc | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/Frameworks/io/src/environment.cc b/Frameworks/io/src/environment.cc index be896165..bdf1ea9f 100644 --- a/Frameworks/io/src/environment.cc +++ b/Frameworks/io/src/environment.cc @@ -5,15 +5,10 @@ namespace oak { - static bool exclude_variable (std::string const& variable) + static bool include_variable (std::string const& variable) { - static std::string const BlackListedPrefixes[] = { "TM_", "OAK_", "DIALOG", "MAKE", "MFLAGS", "GIT_" }; - iterate(prefix, BlackListedPrefixes) - { - if(variable.find(*prefix) == 0) - return true; - } - return false; + static std::set const WhiteListedVariables = { "COMMAND_MODE", "SHELL", "SHLVL", "SSH_AUTH_SOCK", "__CF_USER_TEXT_ENCODING" }; + return variable.find("Apple") == 0 || WhiteListedVariables.find(variable) != WhiteListedVariables.end(); } std::map setup_basic_environment () @@ -32,7 +27,7 @@ namespace oak for(char** pair = *envPtr; pair && *pair; ++pair) { char* value = strchr(*pair, '='); - if(value && *value == '=' && !exclude_variable(std::string(*pair, value))) + if(value && *value == '=' && include_variable(std::string(*pair, value))) res[std::string(*pair, value)] = value + 1; }