Skip to content

Commit a5154b2

Browse files
Merge pull request #7583 from gasbytes/patch-segv
separating two x509_store xmalloc checks
2 parents 3b55176 + 063e480 commit a5154b2

1 file changed

Lines changed: 15 additions & 9 deletions

File tree

src/internal.c

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2460,19 +2460,25 @@ int InitSSL_Ctx(WOLFSSL_CTX* ctx, WOLFSSL_METHOD* method, void* heap)
24602460
return MEMORY_E;
24612461
}
24622462
XMEMSET(ctx->param, 0, sizeof(WOLFSSL_X509_VERIFY_PARAM));
2463-
/* WOLFSSL_X509_LOOKUP and param */
2464-
if ((ctx->x509_store.lookup.dirs =
2465-
(WOLFSSL_BY_DIR*)XMALLOC(sizeof(WOLFSSL_BY_DIR),
2466-
heap, DYNAMIC_TYPE_OPENSSL)) == NULL ||
2467-
(ctx->x509_store.param = (WOLFSSL_X509_VERIFY_PARAM*)XMALLOC(
2468-
sizeof(WOLFSSL_X509_VERIFY_PARAM),
2469-
heap, DYNAMIC_TYPE_OPENSSL)) == NULL) {
2470-
WOLFSSL_MSG("ctx-x509_store.lookup.dir or ctx->x509_store.param memory "
2471-
"allocation error");
2463+
2464+
/* WOLFSSL_X509_LOOKUP */
2465+
if ((ctx->x509_store.lookup.dirs = (WOLFSSL_BY_DIR*)XMALLOC(
2466+
sizeof(WOLFSSL_BY_DIR),
2467+
heap, DYNAMIC_TYPE_OPENSSL)) == NULL) {
2468+
WOLFSSL_MSG("ctx->x509_store.lookup.dirs: allocation error");
24722469
return MEMORY_E;
24732470
}
24742471
XMEMSET(ctx->x509_store.lookup.dirs, 0, sizeof(WOLFSSL_BY_DIR));
2472+
2473+
/* param */
2474+
if ((ctx->x509_store.param = (WOLFSSL_X509_VERIFY_PARAM*)XMALLOC(
2475+
sizeof(WOLFSSL_X509_VERIFY_PARAM),
2476+
heap, DYNAMIC_TYPE_OPENSSL)) == NULL) {
2477+
WOLFSSL_MSG("ctx->x509_store.param: allocation error");
2478+
return MEMORY_E;
2479+
}
24752480
XMEMSET(ctx->x509_store.param, 0, sizeof(WOLFSSL_X509_VERIFY_PARAM));
2481+
24762482
if (wc_InitMutex(&ctx->x509_store.lookup.dirs->lock) != 0) {
24772483
WOLFSSL_MSG("Bad mutex init");
24782484
WOLFSSL_ERROR_VERBOSE(BAD_MUTEX_E);

0 commit comments

Comments
 (0)