diff --git a/src/ssl_load.c b/src/ssl_load.c index ea4ac4e78e..da4279e39e 100644 --- a/src/ssl_load.c +++ b/src/ssl_load.c @@ -5095,9 +5095,9 @@ int wolfSSL_CTX_set_default_verify_paths(WOLFSSL_CTX* ctx) { int ret; #ifdef XGETENV - char* certDir; - char* certFile; - word32 flags; + char* certDir = NULL; + char* certFile = NULL; + word32 flags = 0; #elif !defined(WOLFSSL_SYS_CA_CERTS) (void)ctx; #endif @@ -5105,8 +5105,8 @@ int wolfSSL_CTX_set_default_verify_paths(WOLFSSL_CTX* ctx) WOLFSSL_ENTER("wolfSSL_CTX_set_default_verify_paths"); #ifdef XGETENV - certDir = XGETENV("SSL_CERT_DIR"); - certFile = XGETENV("SSL_CERT_FILE"); + certDir = wc_strdup_ex(XGETENV("SSL_CERT_DIR"), DYNAMIC_TYPE_TMP_BUFFER); + certFile = wc_strdup_ex(XGETENV("SSL_CERT_FILE"), DYNAMIC_TYPE_TMP_BUFFER); flags = WOLFSSL_LOAD_FLAG_PEM_CA_ONLY; if ((certDir != NULL) || (certFile != NULL)) { @@ -5152,6 +5152,10 @@ int wolfSSL_CTX_set_default_verify_paths(WOLFSSL_CTX* ctx) #endif } +#ifdef XGETENV + XFREE(certFile, NULL, DYNAMIC_TYPE_TMP_BUFFER); + XFREE(certDir, NULL, DYNAMIC_TYPE_TMP_BUFFER); +#endif WOLFSSL_LEAVE("wolfSSL_CTX_set_default_verify_paths", ret); return ret; @@ -5267,6 +5271,7 @@ int wolfSSL_SetTmpDH(WOLFSSL* ssl, const unsigned char* p, int pSz, pAlloc = (byte*)XMALLOC(pSz, ssl->heap, DYNAMIC_TYPE_PUBLIC_KEY); gAlloc = (byte*)XMALLOC(gSz, ssl->heap, DYNAMIC_TYPE_PUBLIC_KEY); if ((pAlloc == NULL) || (gAlloc == NULL)) { + /* Memory will be freed below in the (ret != 1) block */ ret = MEMORY_E; } } diff --git a/wolfcrypt/src/wc_port.c b/wolfcrypt/src/wc_port.c index 7ff02abf41..572c20e131 100644 --- a/wolfcrypt/src/wc_port.c +++ b/wolfcrypt/src/wc_port.c @@ -1177,6 +1177,23 @@ int wc_strncasecmp(const char *s1, const char *s2, size_t n) } #endif /* USE_WOLF_STRNCASECMP */ +#ifdef USE_WOLF_STRDUP +char* wc_strdup_ex(const char *src, int memType) { + char *ret = NULL; + int len = 0; + + if (src) { + len = (int)XSTRLEN(src); + ret = (char*)XMALLOC(len, NULL, memType); + if (ret != NULL) { + XMEMCPY(ret, src, len); + } + } + + return ret; +} +#endif + #ifdef WOLFSSL_ATOMIC_OPS #ifdef HAVE_C___ATOMIC diff --git a/wolfssl/wolfcrypt/types.h b/wolfssl/wolfcrypt/types.h index b907e92487..af7f596e9a 100644 --- a/wolfssl/wolfcrypt/types.h +++ b/wolfssl/wolfcrypt/types.h @@ -919,6 +919,15 @@ typedef struct w64wrapper { WOLFSSL_API int wc_strncasecmp(const char *s1, const char *s2, size_t n); #endif + #if !defined(XSTRDUP) && !defined(USE_WOLF_STRDUP) + #define USE_WOLF_STRDUP + #endif + #ifdef USE_WOLF_STRDUP + WOLFSSL_LOCAL char* wc_strdup_ex(const char *src, int memType); + #define wc_strdup(src) wc_strdup_ex(src, DYNAMIC_TYPE_TMP_BUFFER) + #define XSTRDUP(src) wc_strdup(src) + #endif + #if !defined(NO_FILESYSTEM) && !defined(NO_STDIO_FILESYSTEM) #ifndef XGETENV #ifdef NO_GETENV