From 87653e29aa6e95f15499201d6edcc04feb297a2b Mon Sep 17 00:00:00 2001 From: Denis Sergeev Date: Mon, 13 Oct 2025 13:37:52 +0300 Subject: [PATCH 1/2] ftp: use SSL_write_ex() in single_send() Replace SSL_write() with SSL_write_ex() and pass its return value to SSL_get_error(). This preserves the original API contract and avoids signed/unsigned conversion issues when handling errors. Signed-off-by: Denis Sergeev --- ext/ftp/ftp.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/ext/ftp/ftp.c b/ext/ftp/ftp.c index f9c61748efdd..3f9cd63ce65d 100644 --- a/ext/ftp/ftp.c +++ b/ext/ftp/ftp.c @@ -1321,6 +1321,7 @@ static int single_send(ftpbuf_t *ftp, php_socket_t s, void *buf, size_t size) { SSL *handle = NULL; php_socket_t fd; size_t sent; + int ret; if (ftp->use_ssl && ftp->fd == s && ftp->ssl_active) { handle = ftp->ssl_handle; @@ -1333,8 +1334,8 @@ static int single_send(ftpbuf_t *ftp, php_socket_t s, void *buf, size_t size) { } do { - sent = SSL_write(handle, buf, size); - err = SSL_get_error(handle, sent); + ret = SSL_write_ex(handle, buf, size, &sent); + err = SSL_get_error(handle, ret); switch (err) { case SSL_ERROR_NONE: @@ -1343,6 +1344,7 @@ static int single_send(ftpbuf_t *ftp, php_socket_t s, void *buf, size_t size) { case SSL_ERROR_ZERO_RETURN: retry = false; + sent = 0; SSL_shutdown(handle); break; @@ -1366,7 +1368,7 @@ static int single_send(ftpbuf_t *ftp, php_socket_t s, void *buf, size_t size) { return -1; } } while (retry); - return sent; + return (int)sent; #else return my_send_wrapper_with_restart(s, buf, size, 0); #endif From 0173a9d4c92c423645cd0fe61997deadb7cd113c Mon Sep 17 00:00:00 2001 From: Georgij Tsarin Date: Fri, 31 Jul 2026 13:42:06 +0300 Subject: [PATCH 2/2] ftp: widen single_send() return type to ssize_t --- ext/ftp/ftp.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ext/ftp/ftp.c b/ext/ftp/ftp.c index 3f9cd63ce65d..05e49ee97a84 100644 --- a/ext/ftp/ftp.c +++ b/ext/ftp/ftp.c @@ -1314,7 +1314,7 @@ static ssize_t my_recv_wrapper_with_restart(php_socket_t fd, void *buf, size_t s return n; } -static int single_send(ftpbuf_t *ftp, php_socket_t s, void *buf, size_t size) { +static ssize_t single_send(ftpbuf_t *ftp, php_socket_t s, void *buf, size_t size) { #ifdef HAVE_FTP_SSL int err; bool retry = false; @@ -1368,7 +1368,7 @@ static int single_send(ftpbuf_t *ftp, php_socket_t s, void *buf, size_t size) { return -1; } } while (retry); - return (int)sent; + return sent; #else return my_send_wrapper_with_restart(s, buf, size, 0); #endif