ftp: make EPRT connections non-blocking

On platforms where neither accept4 nor fcntl was available, an
EPRT connection did not send the accepted socket as non-blocking.

This became apparent when TLS was in use and the test receive
on shutdown did simply hang.

Reported-by: Denis Goleshchikhin
Fixes #19753
Closes #19851
This commit is contained in:
Stefan Eissing 2025-12-05 14:12:47 +01:00 committed by Daniel Stenberg
parent 15e5ac6da8
commit 891566c72d
No known key found for this signature in database
GPG key ID: 5CC908FDB71E12C2
6 changed files with 231 additions and 8 deletions

View file

@ -2114,15 +2114,22 @@ static CURLcode cf_tcp_accept_connect(struct Curl_cfilter *cf,
curlx_strerror(SOCKERRNO, errbuf, sizeof(errbuf)));
return CURLE_FTP_ACCEPT_FAILED;
}
#if !defined(HAVE_ACCEPT4) && defined(HAVE_FCNTL)
if((fcntl(s_accepted, F_SETFD, FD_CLOEXEC) < 0) ||
(curlx_nonblock(s_accepted, TRUE) < 0)) {
failf(data, "fcntl set CLOEXEC/NONBLOCK: %s",
#ifndef HAVE_ACCEPT4
#ifdef HAVE_FCNTL
if(fcntl(s_accepted, F_SETFD, FD_CLOEXEC) < 0) {
failf(data, "fcntl set CLOEXEC: %s",
curlx_strerror(SOCKERRNO, errbuf, sizeof(errbuf)));
Curl_socket_close(data, cf->conn, s_accepted);
return CURLE_FTP_ACCEPT_FAILED;
}
#endif
#endif /* HAVE_FCNTL */
if(curlx_nonblock(s_accepted, TRUE) < 0) {
failf(data, "set socket NONBLOCK: %s",
curlx_strerror(SOCKERRNO, errbuf, sizeof(errbuf)));
Curl_socket_close(data, cf->conn, s_accepted);
return CURLE_FTP_ACCEPT_FAILED;
}
#endif /* !HAVE_ACCEPT4 */
infof(data, "Connection accepted from server");
/* Replace any filter on SECONDARY with one listening on this socket */