From 51a2f9de17bfadb7f37fa4d8e25b312b6c01c5f3 Mon Sep 17 00:00:00 2001 From: Hideki Miyazaki Date: Tue, 7 Sep 2021 07:15:08 +0900 Subject: [PATCH] return value convention on compatibility layer (#4373) * return value convention * addressed review comments * addressed review comment part2 * fix jenkins failures --- src/ssl.c | 42 ++++++++++++++++++++++++++++++++++++++++++ tests/api.c | 20 +++++++++++++++++++- 2 files changed, 61 insertions(+), 1 deletion(-) diff --git a/src/ssl.c b/src/ssl.c index 8be191cbd..dbb6d2bd6 100644 --- a/src/ssl.c +++ b/src/ssl.c @@ -49375,11 +49375,25 @@ int wolfSSL_CTX_set_alpn_protos(WOLFSSL_CTX *ctx, const unsigned char *p, ctx->alpn_cli_protos = (const unsigned char *)wolfSSL_OPENSSL_memdup(p, p_len, NULL, 0); if (ctx->alpn_cli_protos == NULL) { +#if defined(WOLFSSL_ERROR_CODE_OPENSSL) + /* 0 on success in OpenSSL, non-0 on failure in OpenSSL + * the function reverses the return value convention. + */ + return 1; +#else return SSL_FAILURE; +#endif } ctx->alpn_cli_protos_len = p_len; +#if defined(WOLFSSL_ERROR_CODE_OPENSSL) + /* 0 on success in OpenSSL, non-0 on failure in OpenSSL + * the function reverses the return value convention. + */ + return 0; +#else return WOLFSSL_SUCCESS; +#endif } @@ -49405,12 +49419,26 @@ int wolfSSL_set_alpn_protos(WOLFSSL* ssl, WOLFSSL_ENTER("wolfSSL_set_alpn_protos"); if (ssl == NULL || p_len <= 1) { +#if defined(WOLFSSL_ERROR_CODE_OPENSSL) + /* 0 on success in OpenSSL, non-0 on failure in OpenSSL + * the function reverses the return value convention. + */ + return 1; +#else return WOLFSSL_FAILURE; +#endif } bio = wolfSSL_BIO_new(wolfSSL_BIO_s_mem()); if (bio == NULL) { +#if defined(WOLFSSL_ERROR_CODE_OPENSSL) + /* 0 on success in OpenSSL, non-0 on failure in OpenSSL + * the function reverses the return value convention. + */ + return 1; +#else return WOLFSSL_FAILURE; +#endif } /* convert into comma separated list */ @@ -49421,7 +49449,14 @@ int wolfSSL_set_alpn_protos(WOLFSSL* ssl, if (idx + sz > p_len) { WOLFSSL_MSG("Bad list format"); wolfSSL_BIO_free(bio); + #if defined(WOLFSSL_ERROR_CODE_OPENSSL) + /* 0 on success in OpenSSL, non-0 on failure in OpenSSL + * the function reverses the return value convention. + */ + return 1; + #else return WOLFSSL_FAILURE; + #endif } if (sz > 0) { for (i = 0; i < sz; i++) { @@ -49440,7 +49475,14 @@ int wolfSSL_set_alpn_protos(WOLFSSL* ssl, wolfSSL_UseALPN(ssl, pt, sz, alpn_opt); } wolfSSL_BIO_free(bio); +#if defined(WOLFSSL_ERROR_CODE_OPENSSL) + /* 0 on success in OpenSSL, non-0 on failure in OpenSSL + * the function reverses the return value convention. + */ + return 0; +#else return WOLFSSL_SUCCESS; +#endif } #endif /* !NO_BIO */ #endif /* HAVE_ALPN */ diff --git a/tests/api.c b/tests/api.c index c9dfb0e99..7d64a7822 100644 --- a/tests/api.c +++ b/tests/api.c @@ -33008,8 +33008,26 @@ static void test_wolfSSL_set_options(void) AssertTrue(SSL_set_msg_callback(ssl, msg_cb) == SSL_SUCCESS); SSL_set_msg_callback_arg(ssl, arg); - +#ifdef WOLFSSL_ERROR_CODE_OPENSSL + AssertTrue(SSL_CTX_set_alpn_protos(ctx, protos, len) == 0); +#else AssertTrue(SSL_CTX_set_alpn_protos(ctx, protos, len) == SSL_SUCCESS); +#endif + +#if defined(WOLFSSL_NGINX) || defined(WOLFSSL_HAPROXY) || \ + defined(WOLFSSL_MYSQL_COMPATIBLE) || defined(OPENSSL_ALL) || \ + defined(HAVE_LIGHTY) || defined(HAVE_STUNNEL) + +#if defined(HAVE_ALPN) && !defined(NO_BIO) + +#ifdef WOLFSSL_ERROR_CODE_OPENSSL + AssertTrue(SSL_set_alpn_protos(ssl, protos, len) == 0); +#else + AssertTrue(SSL_set_alpn_protos(ssl, protos, len) == SSL_SUCCESS); +#endif + +#endif /* HAVE_ALPN && !NO_BIO */ +#endif SSL_free(ssl); SSL_CTX_free(ctx);