From 0d289f19724d88e4bebeee20cd1dfc55b61a86c9 Mon Sep 17 00:00:00 2001 From: Kazuki Yamaguchi Date: Fri, 15 Apr 2016 14:15:42 +0900 Subject: ext/openssl: some trivial cleanups ossl_start_ssl(): specify the argument type of the function pointer parameter 'func'. ossl_sslctx_set_ciphers(): use StringValueCStr() because SSL_CTX_set_cipher_list() expects NUL-terminated string. ossl_sslctx_setup(): use just RSTRING_PTR() ossl_ssl_shutdown(): remove an unused variable 'rc' and remove a call to SSL_clear(). This function resets the SSL object to allow another connection, but we don't reuse SSL object for another connection. --- ext/openssl/ossl_ssl.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/ext/openssl/ossl_ssl.c b/ext/openssl/ossl_ssl.c index 416fa91cae..e5f1b73c7c 100644 --- a/ext/openssl/ossl_ssl.c +++ b/ext/openssl/ossl_ssl.c @@ -812,7 +812,7 @@ ossl_sslctx_setup(VALUE self) val = rb_iv_get(self, "@alpn_protocols"); if (!NIL_P(val)) { VALUE rprotos = ssl_encode_npn_protocols(val); - SSL_CTX_set_alpn_protos(ctx, (const unsigned char *)StringValueCStr(rprotos), RSTRING_LENINT(rprotos)); + SSL_CTX_set_alpn_protos(ctx, (const unsigned char *)RSTRING_PTR(rprotos), RSTRING_LENINT(rprotos)); OSSL_Debug("SSL ALPN values added"); } if (RTEST(rb_iv_get(self, "@alpn_select_cb"))) { @@ -947,7 +947,7 @@ ossl_sslctx_set_ciphers(VALUE self, VALUE v) ossl_raise(eSSLError, "SSL_CTX is not initialized."); return Qnil; } - if (!SSL_CTX_set_cipher_list(ctx, RSTRING_PTR(str))) { + if (!SSL_CTX_set_cipher_list(ctx, StringValueCStr(str))) { ossl_raise(eSSLError, "SSL_CTX_set_cipher_list"); } @@ -1147,7 +1147,7 @@ ossl_sslctx_flush_sessions(int argc, VALUE *argv, VALUE self) static void ossl_ssl_shutdown(SSL *ssl) { - int i, rc; + int i; if (ssl) { /* 4 is from SSL_smart_shutdown() of mod_ssl.c (v2.2.19) */ @@ -1157,10 +1157,9 @@ ossl_ssl_shutdown(SSL *ssl) * Ignore the case SSL_shutdown returns -1. Empty handshake_func * must not happen. */ - if ((rc = SSL_shutdown(ssl)) != 0) + if (SSL_shutdown(ssl) != 0) break; } - SSL_clear(ssl); ERR_clear_error(); } } @@ -1271,7 +1270,7 @@ no_exception_p(VALUE opts) } static VALUE -ossl_start_ssl(VALUE self, int (*func)(), const char *funcname, VALUE opts) +ossl_start_ssl(VALUE self, int (*func)(SSL *), const char *funcname, VALUE opts) { SSL *ssl; rb_io_t *fptr; -- cgit v1.2.3