Use foreach loop to match setuid unsafe env vars.

Change-Id: I1e94daefac8e601281f38c7ce29ba3172a4a60bb
This commit is contained in:
Josh Gao 2015-10-01 15:50:16 -07:00
parent 143409d75b
commit a5d5d16c3c
1 changed files with 30 additions and 31 deletions

View File

@ -237,38 +237,37 @@ static bool __is_valid_environment_variable(const char* name) {
static bool __is_unsafe_environment_variable(const char* name) { static bool __is_unsafe_environment_variable(const char* name) {
// None of these should be allowed in setuid programs. // None of these should be allowed in setuid programs.
static const char* const UNSAFE_VARIABLE_NAMES[] = { static constexpr const char* UNSAFE_VARIABLE_NAMES[] = {
"GCONV_PATH", "GCONV_PATH",
"GETCONF_DIR", "GETCONF_DIR",
"HOSTALIASES", "HOSTALIASES",
"JE_MALLOC_CONF", "JE_MALLOC_CONF",
"LD_AOUT_LIBRARY_PATH", "LD_AOUT_LIBRARY_PATH",
"LD_AOUT_PRELOAD", "LD_AOUT_PRELOAD",
"LD_AUDIT", "LD_AUDIT",
"LD_DEBUG", "LD_DEBUG",
"LD_DEBUG_OUTPUT", "LD_DEBUG_OUTPUT",
"LD_DYNAMIC_WEAK", "LD_DYNAMIC_WEAK",
"LD_LIBRARY_PATH", "LD_LIBRARY_PATH",
"LD_ORIGIN_PATH", "LD_ORIGIN_PATH",
"LD_PRELOAD", "LD_PRELOAD",
"LD_PROFILE", "LD_PROFILE",
"LD_SHOW_AUXV", "LD_SHOW_AUXV",
"LD_USE_LOAD_BIAS", "LD_USE_LOAD_BIAS",
"LOCALDOMAIN", "LOCALDOMAIN",
"LOCPATH", "LOCPATH",
"MALLOC_CHECK_", "MALLOC_CHECK_",
"MALLOC_CONF", "MALLOC_CONF",
"MALLOC_TRACE", "MALLOC_TRACE",
"NIS_PATH", "NIS_PATH",
"NLSPATH", "NLSPATH",
"RESOLV_HOST_CONF", "RESOLV_HOST_CONF",
"RES_OPTIONS", "RES_OPTIONS",
"TMPDIR", "TMPDIR",
"TZDIR", "TZDIR",
nullptr
}; };
for (size_t i = 0; UNSAFE_VARIABLE_NAMES[i] != nullptr; ++i) { for (const auto& unsafe_variable_name : UNSAFE_VARIABLE_NAMES) {
if (env_match(name, UNSAFE_VARIABLE_NAMES[i]) != nullptr) { if (env_match(name, unsafe_variable_name) != nullptr) {
return true; return true;
} }
} }