Last active
January 29, 2017 08:43
-
-
Save vsajip/04c8db39c8e8da31c0ed3be646b06f08 to your computer and use it in GitHub Desktop.
Crude fix for libtls issue #266
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- tls/tls.c 2017-01-25 18:20:41.087748566 +0000 | |
+++ /home/vinay/tmp/tls.c 2017-01-29 08:26:00.343170297 +0000 | |
@@ -635,6 +635,21 @@ | |
return (rv); | |
} | |
+static BOOL | |
+socket_is_valid(SOCKET fd) | |
+{ | |
+ fd_set fds; | |
+ int rc; | |
+ TIMEVAL t; | |
+ | |
+ ZeroMemory(&fds, sizeof(fds)); | |
+ t.tv_sec = t.tv_usec = 0; | |
+ fds.fd_count = 1; | |
+ fds.fd_array[0] = fd; | |
+ rc = select(1, &fds, &fds, &fds, &t); | |
+ return rc >= 0; | |
+} | |
+ | |
int | |
tls_close(struct tls *ctx) | |
{ | |
@@ -651,12 +666,14 @@ | |
if (ctx->ssl_conn != NULL) { | |
ERR_clear_error(); | |
- ssl_ret = SSL_shutdown(ctx->ssl_conn); | |
- if (ssl_ret < 0) { | |
- rv = tls_ssl_error(ctx, ctx->ssl_conn, ssl_ret, | |
- "shutdown"); | |
- if (rv == TLS_WANT_POLLIN || rv == TLS_WANT_POLLOUT) | |
- goto out; | |
+ if (socket_is_valid(ctx->ssl_conn->wbio->num)) { | |
+ ssl_ret = SSL_shutdown(ctx->ssl_conn); | |
+ if (ssl_ret < 0) { | |
+ rv = tls_ssl_error(ctx, ctx->ssl_conn, ssl_ret, | |
+ "shutdown"); | |
+ if (rv == TLS_WANT_POLLIN || rv == TLS_WANT_POLLOUT) | |
+ goto out; | |
+ } | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment