From 12a5cb45fbc148acc3b6fe7c37030a3aded26d76 Mon Sep 17 00:00:00 2001 From: gasbytes Date: Thu, 23 May 2024 23:04:00 +0200 Subject: [PATCH 1/3] separating two x509_store xmalloc checks --- src/internal.c | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/src/internal.c b/src/internal.c index 2f75fb297..5ea61eccd 100644 --- a/src/internal.c +++ b/src/internal.c @@ -2460,19 +2460,21 @@ 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); From 3f96d14b32bc13f6878ebac56e5e8e8343906efb Mon Sep 17 00:00:00 2001 From: gasbytes Date: Fri, 24 May 2024 00:12:38 +0200 Subject: [PATCH 2/3] 80 characters limit fix --- src/internal.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/internal.c b/src/internal.c index 5ea61eccd..ff120e115 100644 --- a/src/internal.c +++ b/src/internal.c @@ -2462,14 +2462,18 @@ int InitSSL_Ctx(WOLFSSL_CTX* ctx, WOLFSSL_METHOD* method, void* heap) XMEMSET(ctx->param, 0, sizeof(WOLFSSL_X509_VERIFY_PARAM)); /* WOLFSSL_X509_LOOKUP */ - if ((ctx->x509_store.lookup.dirs = (WOLFSSL_BY_DIR*)XMALLOC(sizeof(WOLFSSL_BY_DIR), heap, DYNAMIC_TYPE_OPENSSL)) == NULL) { + 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) { + 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; } From 063e48014a2a02f6a516da10c766de56c08c79fa Mon Sep 17 00:00:00 2001 From: gasbytes Date: Fri, 24 May 2024 17:52:54 +0200 Subject: [PATCH 3/3] fix tabs and spaces --- src/internal.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/internal.c b/src/internal.c index ff120e115..b4f822119 100644 --- a/src/internal.c +++ b/src/internal.c @@ -2463,17 +2463,17 @@ int InitSSL_Ctx(WOLFSSL_CTX* ctx, WOLFSSL_METHOD* method, void* heap) /* 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"); + 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) { + sizeof(WOLFSSL_X509_VERIFY_PARAM), + heap, DYNAMIC_TYPE_OPENSSL)) == NULL) { WOLFSSL_MSG("ctx->x509_store.param: allocation error"); return MEMORY_E; }