From 64caf325f8d538ed98325001d8a4a5aded0ec186 Mon Sep 17 00:00:00 2001 From: Takashi Kojo Date: Tue, 28 Nov 2017 10:16:24 +0900 Subject: [PATCH] add ctx == NULL checks, fix spacing --- src/ssl.c | 11 +++++++++-- tests/api.c | 12 ++++++------ 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/src/ssl.c b/src/ssl.c index afe702cbc..1a52929dd 100644 --- a/src/ssl.c +++ b/src/ssl.c @@ -11471,14 +11471,17 @@ int wolfSSL_set_compression(WOLFSSL* ssl) { WOLFSSL_ENTER("wolfSSL_CTX_get_options"); WOLFSSL_MSG("wolfSSL options are set through API calls and macros"); + if(ctx == NULL)return SSL_FAILURE; return ctx->mask; } long wolfSSL_CTX_set_options(WOLFSSL_CTX* ctx, long opt) { - WOLFSSL *ssl = wolfSSL_new(ctx); + WOLFSSL *ssl; WOLFSSL_ENTER("SSL_CTX_set_options"); + if(ctx == NULL)return SSL_FAILURE; + ssl = wolfSSL_new(ctx); if(ssl == NULL)return SSL_FAILURE; ctx->mask = wolfSSL_set_options(ssl, opt); wolfSSL_free(ssl); @@ -11583,6 +11586,8 @@ int wolfSSL_set_compression(WOLFSSL* ssl) void wolfSSL_X509_STORE_CTX_set_verify_cb(WOLFSSL_X509_STORE_CTX *ctx, WOLFSSL_X509_STORE_CTX_verify_cb verify_cb) { + WOLFSSL_ENTER("wolfSSL_X509_STORE_CTX_set_verify_cb"); + if(ctx == NULL)return; ctx->verify_cb = verify_cb; } #endif @@ -17076,7 +17081,7 @@ long wolfSSL_set_options(WOLFSSL* ssl, long op) long wolfSSL_get_options(const WOLFSSL* ssl) { WOLFSSL_ENTER("wolfSSL_get_options"); - + if(ssl == NULL)return WOLFSSL_FAILURE; return ssl->options.mask; } @@ -26444,6 +26449,8 @@ void *wolfSSL_OPENSSL_memdup(const void *data, size_t siz, const char* file, int int wolfSSL_CTX_set_alpn_protos(WOLFSSL_CTX *ctx, const unsigned char *p, unsigned int p_len) { + WOLFSSL_ENTER("wolfSSL_CTX_set_alpn_protos"); + if(ctx == NULL)return WOLFSSL_FAILURE; if((void *)ctx->alpn_cli_protos != NULL) wolfSSL_OPENSSL_free((void *)ctx->alpn_cli_protos); ctx->alpn_cli_protos = diff --git a/tests/api.c b/tests/api.c index b588e375a..b435ff319 100644 --- a/tests/api.c +++ b/tests/api.c @@ -10517,10 +10517,10 @@ static void test_wolfSSL_set_options(void) #if defined(OPENSSL_EXTRA) && !defined(NO_CERTS) static int verify_cb(int ok, X509_STORE_CTX *ctx) { - (void) ok; - (void) ctx; - printf("ENTER verify_cb\n"); - return SSL_SUCCESS; + (void) ok; + (void) ctx; + printf("ENTER verify_cb\n"); + return SSL_SUCCESS; } #endif @@ -10530,8 +10530,8 @@ static void test_wolfSSL_X509_STORE_CTX(void) X509_STORE_CTX *ctx = NULL ; printf(testingFmt, "test_wolfSSL_X509_STORE_CTX(()"); - AssertNotNull(ctx = X509_STORE_CTX_new()); - X509_STORE_CTX_set_verify_cb(ctx, (void *)verify_cb); + AssertNotNull(ctx = X509_STORE_CTX_new()); + X509_STORE_CTX_set_verify_cb(ctx, (void *)verify_cb); X509_STORE_CTX_free(ctx); printf(resultFmt, passed); #endif