summaryrefslogtreecommitdiff
path: root/src/lib/libtls/tls.c
diff options
context:
space:
mode:
authorjsing <>2017-01-26 12:56:37 +0000
committerjsing <>2017-01-26 12:56:37 +0000
commitfaeda34edddb798c605b02be985707c383fc2619 (patch)
treeb6f097154c11d0ef88cefdbed8094e57584a2602 /src/lib/libtls/tls.c
parent5f4d6ed4e05cb127aa9702893fbc6baf9ee43f35 (diff)
downloadopenbsd-faeda34edddb798c605b02be985707c383fc2619.tar.gz
openbsd-faeda34edddb798c605b02be985707c383fc2619.tar.bz2
openbsd-faeda34edddb798c605b02be985707c383fc2619.zip
Use a flag to track when we need to call SSL_shutdown(). This avoids an
issue where by calling tls_close() on a TLS context that has not attempted a handshake, results in an unexpected failure. Reported by Vinay Sajip. ok beck@
Diffstat (limited to 'src/lib/libtls/tls.c')
-rw-r--r--src/lib/libtls/tls.c5
1 files changed, 3 insertions, 2 deletions
diff --git a/src/lib/libtls/tls.c b/src/lib/libtls/tls.c
index c028d19539..9b03c2b6f0 100644
--- a/src/lib/libtls/tls.c
+++ b/src/lib/libtls/tls.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: tls.c,v 1.58 2017/01/22 08:27:50 claudio Exp $ */ 1/* $OpenBSD: tls.c,v 1.59 2017/01/26 12:56:37 jsing Exp $ */
2/* 2/*
3 * Copyright (c) 2014 Joel Sing <jsing@openbsd.org> 3 * Copyright (c) 2014 Joel Sing <jsing@openbsd.org>
4 * 4 *
@@ -649,7 +649,7 @@ tls_close(struct tls *ctx)
649 goto out; 649 goto out;
650 } 650 }
651 651
652 if (ctx->ssl_conn != NULL) { 652 if (ctx->state & TLS_SSL_NEEDS_SHUTDOWN) {
653 ERR_clear_error(); 653 ERR_clear_error();
654 ssl_ret = SSL_shutdown(ctx->ssl_conn); 654 ssl_ret = SSL_shutdown(ctx->ssl_conn);
655 if (ssl_ret < 0) { 655 if (ssl_ret < 0) {
@@ -658,6 +658,7 @@ tls_close(struct tls *ctx)
658 if (rv == TLS_WANT_POLLIN || rv == TLS_WANT_POLLOUT) 658 if (rv == TLS_WANT_POLLIN || rv == TLS_WANT_POLLOUT)
659 goto out; 659 goto out;
660 } 660 }
661 ctx->state &= ~TLS_SSL_NEEDS_SHUTDOWN;
661 } 662 }
662 663
663 if (ctx->socket != -1) { 664 if (ctx->socket != -1) {