From 5efa660b41ab05971901f3a7b19e3890ea1e8884 Mon Sep 17 00:00:00 2001 From: Esun Kim Date: Thu, 18 Jul 2019 17:01:45 -0700 Subject: [PATCH] Remove warning for old linux without secure_getenv --- src/core/lib/gpr/env_linux.cc | 31 ++++++++++--------------------- src/core/lib/gpr/env_posix.cc | 5 ----- 2 files changed, 10 insertions(+), 26 deletions(-) diff --git a/src/core/lib/gpr/env_linux.cc b/src/core/lib/gpr/env_linux.cc index 3a3aa541672..6a78dc14155 100644 --- a/src/core/lib/gpr/env_linux.cc +++ b/src/core/lib/gpr/env_linux.cc @@ -38,19 +38,20 @@ #include "src/core/lib/gpr/string.h" #include "src/core/lib/gpr/useful.h" -static const char* gpr_getenv_silent(const char* name, char** dst) { - const char* insecure_func_used = nullptr; +char* gpr_getenv(const char* name) { char* result = nullptr; #if defined(GPR_BACKWARDS_COMPATIBILITY_MODE) typedef char* (*getenv_type)(const char*); - static getenv_type getenv_func = NULL; + static getenv_type getenv_func = nullptr; /* Check to see which getenv variant is supported (go from most * to least secure) */ - const char* names[] = {"secure_getenv", "__secure_getenv", "getenv"}; - for (size_t i = 0; getenv_func == NULL && i < GPR_ARRAY_SIZE(names); i++) { - getenv_func = (getenv_type)dlsym(RTLD_DEFAULT, names[i]); - if (getenv_func != NULL && strstr(names[i], "secure") == NULL) { - insecure_func_used = names[i]; + if (getenv_func == nullptr) { + const char* names[] = {"secure_getenv", "__secure_getenv", "getenv"}; + for (size_t i = 0; i < GPR_ARRAY_SIZE(names); i++) { + getenv_func = (getenv_type)dlsym(RTLD_DEFAULT, names[i]); + if (getenv_func != nullptr) { + break; + } } } result = getenv_func(name); @@ -58,20 +59,8 @@ static const char* gpr_getenv_silent(const char* name, char** dst) { result = secure_getenv(name); #else result = getenv(name); - insecure_func_used = "getenv"; #endif - *dst = result == nullptr ? result : gpr_strdup(result); - return insecure_func_used; -} - -char* gpr_getenv(const char* name) { - char* result = nullptr; - const char* insecure_func_used = gpr_getenv_silent(name, &result); - if (insecure_func_used != nullptr) { - gpr_log(GPR_DEBUG, "Warning: insecure environment read function '%s' used", - insecure_func_used); - } - return result; + return result == nullptr ? result : gpr_strdup(result); } void gpr_setenv(const char* name, const char* value) { diff --git a/src/core/lib/gpr/env_posix.cc b/src/core/lib/gpr/env_posix.cc index 30ddc50f682..232095b4e22 100644 --- a/src/core/lib/gpr/env_posix.cc +++ b/src/core/lib/gpr/env_posix.cc @@ -29,11 +29,6 @@ #include #include "src/core/lib/gpr/string.h" -const char* gpr_getenv_silent(const char* name, char** dst) { - *dst = gpr_getenv(name); - return nullptr; -} - char* gpr_getenv(const char* name) { char* result = getenv(name); return result == nullptr ? result : gpr_strdup(result);