From e7ffba21a1a2f858930b6d2ecb2c69e9fbfd3a29 Mon Sep 17 00:00:00 2001 From: "Christoph M. Becker" Date: Wed, 24 Mar 2021 14:42:53 +0100 Subject: [PATCH 1/4] Fix #80880: SSL_read on shutdown, ftp/proc_open When `SSL_read()` after `SSL_shutdown()` fails with `SSL_ERROR_SYSCALL`, we should not warn about this on Windows for `WSAECONNABORTED`. --- ext/ftp/ftp.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/ext/ftp/ftp.c b/ext/ftp/ftp.c index 5bb359b353a95..e4d88c483ac3e 100644 --- a/ext/ftp/ftp.c +++ b/ext/ftp/ftp.c @@ -1931,6 +1931,14 @@ static void ftp_ssl_shutdown(ftpbuf_t *ftp, php_socket_t fd, SSL *ssl_handle) { /* SSL wants a write. Really odd. Let's bail out. */ done = 1; break; +# ifdef PHP_WIN32 + case SSL_ERROR_SYSCALL: + if (WSAGetLastError() == WSAECONNABORTED) { + /* suppress spurious warning if connection is aborted */ + done = 1; + } + break; +# endif default: if ((sslerror = ERR_get_error())) { ERR_error_string_n(sslerror, buf, sizeof(buf)); From 2ad2e90b0d5257df70f71ee11712b82883fa8d25 Mon Sep 17 00:00:00 2001 From: "Christoph M. Becker" Date: Thu, 25 Mar 2021 19:07:04 +0100 Subject: [PATCH 2/4] Only break on WSAECONNABORTED --- ext/ftp/ftp.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/ext/ftp/ftp.c b/ext/ftp/ftp.c index e4d88c483ac3e..5341c7434cdf9 100644 --- a/ext/ftp/ftp.c +++ b/ext/ftp/ftp.c @@ -1936,8 +1936,9 @@ static void ftp_ssl_shutdown(ftpbuf_t *ftp, php_socket_t fd, SSL *ssl_handle) { if (WSAGetLastError() == WSAECONNABORTED) { /* suppress spurious warning if connection is aborted */ done = 1; + break; } - break; + /* fallthrough */ # endif default: if ((sslerror = ERR_get_error())) { From c163f269b4596fbeb37519bab71d3a181d21b806 Mon Sep 17 00:00:00 2001 From: "Christoph M. Becker" Date: Tue, 30 Mar 2021 15:10:23 +0200 Subject: [PATCH 3/4] Unconditionally bail out on SSL_ERROR_SYSCALL Signed-off-by: Christoph M. Becker --- ext/ftp/ftp.c | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/ext/ftp/ftp.c b/ext/ftp/ftp.c index 5341c7434cdf9..5eb409990f379 100644 --- a/ext/ftp/ftp.c +++ b/ext/ftp/ftp.c @@ -1931,15 +1931,11 @@ static void ftp_ssl_shutdown(ftpbuf_t *ftp, php_socket_t fd, SSL *ssl_handle) { /* SSL wants a write. Really odd. Let's bail out. */ done = 1; break; -# ifdef PHP_WIN32 case SSL_ERROR_SYSCALL: - if (WSAGetLastError() == WSAECONNABORTED) { - /* suppress spurious warning if connection is aborted */ - done = 1; - break; - } - /* fallthrough */ -# endif + /* Something went totally wrong; bail out to avoid raising + a spurious warning. */ + done = 1; + break; default: if ((sslerror = ERR_get_error())) { ERR_error_string_n(sslerror, buf, sizeof(buf)); From ed6258800e3d5659e8d46807e1647d306cddd2fa Mon Sep 17 00:00:00 2001 From: "Christoph M. Becker" Date: Tue, 6 Apr 2021 12:44:42 +0200 Subject: [PATCH 4/4] Clarify comment --- ext/ftp/ftp.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/ext/ftp/ftp.c b/ext/ftp/ftp.c index 5eb409990f379..f2da6e5153fdb 100644 --- a/ext/ftp/ftp.c +++ b/ext/ftp/ftp.c @@ -1932,8 +1932,9 @@ static void ftp_ssl_shutdown(ftpbuf_t *ftp, php_socket_t fd, SSL *ssl_handle) { done = 1; break; case SSL_ERROR_SYSCALL: - /* Something went totally wrong; bail out to avoid raising - a spurious warning. */ + /* most likely the peer closed the connection without + sending a close_notify shutdown alert; + bail out to avoid raising a spurious warning */ done = 1; break; default: