Skip to content

Commit

Permalink
SNOW-817193 Bug fix: crash with OCSP validation
Browse files Browse the repository at this point in the history
  • Loading branch information
Harry Xi authored May 17, 2023
2 parents 911a99f + f80819c commit 6d6b544
Show file tree
Hide file tree
Showing 5 changed files with 82 additions and 4 deletions.
3 changes: 2 additions & 1 deletion deps/curl-7.88.1/lib/vtls/sf_ocsp.c
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ CURLcode encodeUrlData(const char *url_data, size_t data_size, char** outptr, si
// character needs to be encoded as %xx
size_t buf_len = data_size * 3 + 1;
char* encode_buf = NULL;
char* cur_ptr = encode_buf;
char* cur_ptr = NULL;
size_t enc_len = 0;
size_t pos = 0;

Expand All @@ -293,6 +293,7 @@ CURLcode encodeUrlData(const char *url_data, size_t data_size, char** outptr, si
{
return CURLE_OUT_OF_MEMORY;
}
cur_ptr = encode_buf;

// encode all special characters
for (pos = 0; pos < data_size; pos++)
Expand Down
2 changes: 1 addition & 1 deletion scripts/build_curl.bat
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
:: - vs14 / vs15

@echo off
set CURL_VERSION=7.88.1.1
set CURL_VERSION=7.88.1.2
call %*
goto :EOF

Expand Down
2 changes: 1 addition & 1 deletion scripts/build_curl.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ function usage() {
set -o pipefail

CURL_DIR=7.88.1
CURL_VERSION=${CURL_DIR}.1
CURL_VERSION=${CURL_DIR}.2

DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
source $DIR/_init.sh
Expand Down
72 changes: 72 additions & 0 deletions tests/test_connect.c
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,76 @@ void test_connect_with_full_parameters(void **unused) {
snowflake_term(sf); // purge snowflake context
}

void setCacheFile(char *cache_file)
{
#ifdef __linux__
char *home_env = getenv("HOME");
strcpy(cache_file, (home_env == NULL ? (char*)"/tmp" : home_env));
strcat(cache_file, "/.cache");
strcat(cache_file, "/snowflake");
strcat(cache_file, "/ocsp_response_cache.json");
#elif defined(__APPLE__)
char *home_env = getenv("HOME");
strcpy(cache_file, (home_env == NULL ? (char*)"/tmp" : home_env));
strcat(cache_file, "/Library");
strcat(cache_file, "/Caches");
strcat(cache_file, "/Snowflake");
strcat(cache_file, "/ocsp_response_cache.json");
#elif defined(_WIN32)
char *home_env = getenv("USERPROFILE");
if (home_env == NULL)
{
home_env = getenv("TMP");
if (home_env == NULL)
{
home_env = getenv("TEMP");
}
}
strcpy(cache_file, (home_env == NULL ? (char*)"c:\\temp" : home_env));
strcat(cache_file, "\\AppData");
strcat(cache_file, "\\Local");
strcat(cache_file, "\\Snowflake");
strcat(cache_file, "\\Caches");
strcat(cache_file, "\\ocsp_response_cache.json");
#endif
}

/**
* Test connection with OCSP cache server off
*/
void test_connect_with_ocsp_cache_server_off(void **unused) {
char cache_file[4096];
setCacheFile(cache_file);
remove(cache_file);
sf_setenv("SF_OCSP_RESPONSE_CACHE_SERVER_ENABLED", "false");
SF_CONNECT *sf = setup_snowflake_connection();

SF_STATUS status = snowflake_connect(sf);
if (status != SF_STATUS_SUCCESS) {
dump_error(&(sf->error));
}
assert_int_equal(status, SF_STATUS_SUCCESS);
snowflake_term(sf); // purge snowflake context
}

/**
* Test connection with OCSP cache server on
*/
void test_connect_with_ocsp_cache_server_on(void **unused) {
char cache_file[4096];
setCacheFile(cache_file);
remove(cache_file);
sf_setenv("SF_OCSP_RESPONSE_CACHE_SERVER_ENABLED", "true");
SF_CONNECT *sf = setup_snowflake_connection();

SF_STATUS status = snowflake_connect(sf);
if (status != SF_STATUS_SUCCESS) {
dump_error(&(sf->error));
}
assert_int_equal(status, SF_STATUS_SUCCESS);
snowflake_term(sf); // purge snowflake context
}

/**
* Test connection with proxy parameter
* We don't really test with proxy because that would need a proxy server to be
Expand Down Expand Up @@ -130,6 +200,8 @@ int main(void) {
cmocka_unit_test(test_no_connection_parameters),
cmocka_unit_test(test_connect_with_minimum_parameters),
cmocka_unit_test(test_connect_with_full_parameters),
cmocka_unit_test(test_connect_with_ocsp_cache_server_off),
cmocka_unit_test(test_connect_with_ocsp_cache_server_on),
cmocka_unit_test(test_connect_with_proxy),
};
int ret = cmocka_run_group_tests(tests, NULL, NULL);
Expand Down
7 changes: 6 additions & 1 deletion tests/test_unit_oob.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ void test_oob(void **) {

SF_SETTINGS testcase[] = {
// prod

{
"sfctest0.snowflakecomputing.com",
"443",
Expand All @@ -65,6 +66,7 @@ void test_oob(void **) {
"prod",
"0"
},

// prod
{
"sfctest0.east-us-2.azure.snowflakecomputing.com",
Expand Down Expand Up @@ -309,7 +311,10 @@ void test_simba(void **) {

int main() {
const struct CMUnitTest tests[] = {
cmocka_unit_test(test_oob),
// Disable OOB test for now due to the certificate issue on telemetry endpoint
// Have sdk issue 376 to follow up and will revisit this when it's solved
// https://github.com/snowflakedb/snowflake-sdks-drivers-issues-teamwork/issues/376
// cmocka_unit_test(test_oob),
cmocka_unit_test(test_dsn),
cmocka_unit_test(test_simba),
};
Expand Down

0 comments on commit 6d6b544

Please sign in to comment.