Skip to content

Commit

Permalink
Merge pull request #7583 from gasbytes/patch-segv
Browse files Browse the repository at this point in the history
separating two x509_store xmalloc checks
  • Loading branch information
julek-wolfssl authored May 24, 2024
2 parents 3b55176 + 063e480 commit a5154b2
Showing 1 changed file with 15 additions and 9 deletions.
24 changes: 15 additions & 9 deletions src/internal.c
Original file line number Diff line number Diff line change
Expand Up @@ -2460,19 +2460,25 @@ int InitSSL_Ctx(WOLFSSL_CTX* ctx, WOLFSSL_METHOD* method, void* heap)
return MEMORY_E;
}
XMEMSET(ctx->param, 0, sizeof(WOLFSSL_X509_VERIFY_PARAM));
/* WOLFSSL_X509_LOOKUP and param */
if ((ctx->x509_store.lookup.dirs =
(WOLFSSL_BY_DIR*)XMALLOC(sizeof(WOLFSSL_BY_DIR),
heap, DYNAMIC_TYPE_OPENSSL)) == NULL ||
(ctx->x509_store.param = (WOLFSSL_X509_VERIFY_PARAM*)XMALLOC(
sizeof(WOLFSSL_X509_VERIFY_PARAM),
heap, DYNAMIC_TYPE_OPENSSL)) == NULL) {
WOLFSSL_MSG("ctx-x509_store.lookup.dir or ctx->x509_store.param memory "
"allocation error");

/* WOLFSSL_X509_LOOKUP */
if ((ctx->x509_store.lookup.dirs = (WOLFSSL_BY_DIR*)XMALLOC(
sizeof(WOLFSSL_BY_DIR),
heap, DYNAMIC_TYPE_OPENSSL)) == NULL) {
WOLFSSL_MSG("ctx->x509_store.lookup.dirs: allocation error");
return MEMORY_E;
}
XMEMSET(ctx->x509_store.lookup.dirs, 0, sizeof(WOLFSSL_BY_DIR));

/* param */
if ((ctx->x509_store.param = (WOLFSSL_X509_VERIFY_PARAM*)XMALLOC(
sizeof(WOLFSSL_X509_VERIFY_PARAM),
heap, DYNAMIC_TYPE_OPENSSL)) == NULL) {
WOLFSSL_MSG("ctx->x509_store.param: allocation error");
return MEMORY_E;
}
XMEMSET(ctx->x509_store.param, 0, sizeof(WOLFSSL_X509_VERIFY_PARAM));

if (wc_InitMutex(&ctx->x509_store.lookup.dirs->lock) != 0) {
WOLFSSL_MSG("Bad mutex init");
WOLFSSL_ERROR_VERBOSE(BAD_MUTEX_E);
Expand Down

0 comments on commit a5154b2

Please sign in to comment.