Skip to content

Commit

Permalink
fix issue of sf_getenv_s on Windows with environment variable not bei…
Browse files Browse the repository at this point in the history
…ng set
  • Loading branch information
sfc-gh-ext-simba-hx committed Jul 9, 2024
1 parent 3177f52 commit 58dd45a
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 10 deletions.
6 changes: 4 additions & 2 deletions lib/platform.c
Original file line number Diff line number Diff line change
Expand Up @@ -270,8 +270,10 @@ int STDCALL sf_setenv(const char *name, const char *value) {

char * STDCALL sf_getenv_s(const char *name, char *outbuf, size_t bufsize) {
#ifdef _WIN32
size_t len;
return getenv_s(&len, outbuf, bufsize, name) ? NULL : outbuf;
size_t len = 0;
// SNOW-1526802 on Windows environment variable can't be set to empty
// and getenv_s returns 0 with length of 0 for environment variables not being set
return getenv_s(&len, outbuf, bufsize, name) || (len == 0) ? NULL : outbuf;
#else
char* envval = getenv(name);
if (!envval)
Expand Down
8 changes: 0 additions & 8 deletions tests/test_unit_proxy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,6 @@ void test_proxy_empty(void **unused)

void test_allproxy_noproxy_fromenv(void **unused)
{
SKIP_IF_PROXY_ENV_IS_SET;

sf_setenv("all_proxy", "https://someuser:[email protected]:5050");
sf_setenv("no_proxy", "proxyserver.com");
test_proxy_parts_equality("", "someuser", "somepwd", "somewhere.com", 5050, Proxy::Protocol::HTTPS, "proxyserver.com", true);
Expand All @@ -77,26 +75,20 @@ void test_allproxy_noproxy_fromenv(void **unused)

void test_httpsproxy_fromenv(void **unused)
{
SKIP_IF_PROXY_ENV_IS_SET;

sf_setenv("https_proxy", "https://someuser:[email protected]:5050");
test_proxy_parts_equality("", "someuser", "somepwd", "somewhere.com", 5050, Proxy::Protocol::HTTPS, "", true);
sf_unsetenv("https_proxy");
}

void test_httpproxy_fromenv(void **unused)
{
SKIP_IF_PROXY_ENV_IS_SET;

sf_setenv("http_proxy", "http://username:[email protected]:80");
test_proxy_parts_equality("", "username", "password", "proxyserver.company.com", 80, Proxy::Protocol::HTTP, "", true);
sf_unsetenv("http_proxy");
}

void test_noproxy_fromenv(void **unused)
{
SKIP_IF_PROXY_ENV_IS_SET;

sf_setenv("NO_PROXY", "proxyserver.company.com");
test_proxy_parts_equality("", "", "", "", 0, Proxy::Protocol::NONE, "proxyserver.company.com", true);
sf_unsetenv("NO_PROXY");
Expand Down

0 comments on commit 58dd45a

Please sign in to comment.