Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Code sonar cleanup #7782

Merged
merged 4 commits into from
Jul 30, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions src/ssl_load.c
Original file line number Diff line number Diff line change
Expand Up @@ -5121,18 +5121,18 @@ 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

WOLFSSL_ENTER("wolfSSL_CTX_set_default_verify_paths");

#ifdef XGETENV
certDir = XGETENV("SSL_CERT_DIR");
certFile = XGETENV("SSL_CERT_FILE");
certDir = wc_strdup(XGETENV("SSL_CERT_DIR"), DYNAMIC_TYPE_TMP_BUFFER);
certFile = wc_strdup(XGETENV("SSL_CERT_FILE"), DYNAMIC_TYPE_TMP_BUFFER);
flags = WOLFSSL_LOAD_FLAG_PEM_CA_ONLY;

if ((certDir != NULL) || (certFile != NULL)) {
Expand Down Expand Up @@ -5178,6 +5178,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;
Expand Down Expand Up @@ -5293,6 +5297,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;
}
}
Expand Down
15 changes: 15 additions & 0 deletions wolfcrypt/src/wc_port.c
Original file line number Diff line number Diff line change
Expand Up @@ -1177,6 +1177,21 @@ int wc_strncasecmp(const char *s1, const char *s2, size_t n)
}
#endif /* USE_WOLF_STRNCASECMP */

char* wc_strdup(const char *src, int memType) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should not be always exposed... It needs to be conditional based on #ifdef XGETENV or possibly another macro like USE_WOLF_STRDUP. I'd like to see this strdup function perfectly match the stdlib strdup API. Also consider fixing #define BUF_strdup strdup to use it...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

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;
}

#ifdef WOLFSSL_ATOMIC_OPS

#ifdef HAVE_C___ATOMIC
Expand Down
1 change: 1 addition & 0 deletions wolfssl/wolfcrypt/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -917,6 +917,7 @@ typedef struct w64wrapper {
WOLFSSL_API int wc_strncasecmp(const char *s1, const char *s2, size_t n);
#endif

WOLFSSL_API char* wc_strdup(const char *src, int memType);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should not be public... Please make WOLFSSL_LOCAL

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

#if !defined(NO_FILESYSTEM) && !defined(NO_STDIO_FILESYSTEM)
#ifndef XGETENV
#ifdef NO_GETENV
Expand Down