|
|
|
@ -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) { |
|
|
|
|