From: Bernd Edlinger Date: Sat, 13 Jan 2018 17:41:08 +0000 (+0100) Subject: Explicitly shut the socket down in s_client X-Git-Tag: OpenSSL_1_1_0h~136 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=70fdff68ce9be51cf59c23e1d1a43dcaf8264bbb;p=oweals%2Fopenssl.git Explicitly shut the socket down in s_client Reviewed-by: Richard Levitte (Merged from https://github.com/openssl/openssl/pull/5072) (cherry picked from commit 26ec943e020c0db6a25e6d155ba318270eff0fd7) --- diff --git a/apps/s_client.c b/apps/s_client.c index fab007a86a..d1605454b9 100644 --- a/apps/s_client.c +++ b/apps/s_client.c @@ -2471,6 +2471,17 @@ int s_client_main(int argc, char **argv) */ Sleep(50); #endif + /* + * If we ended with an alert being sent, but still with data in the + * network buffer to be read, then calling BIO_closesocket() will + * result in a TCP-RST being sent. On some platforms (notably + * Windows) then this will result in the peer immediately abandoning + * the connection including any buffered alert data before it has + * had a chance to be read. Shutting down the sending side first, + * and then closing the socket sends TCP-FIN first followed by + * TCP-RST. This seems to allow the peer to read the alert data. + */ + shutdown(SSL_get_fd(con), 1); /* SHUT_WR */ BIO_closesocket(SSL_get_fd(con)); end: if (con != NULL) {