mirror of
https://github.com/curl/curl.git
synced 2026-08-06 14:36:14 +03:00
cf-socket: use SOCK_CLOEXEC in socket_open when available
To close the possible race between socket() and fcntl(), we use SOCK_CLOEXEC instead of fcntl() when it is available. Closes #20442
This commit is contained in:
parent
0f042efcb1
commit
05367694ec
1 changed files with 5 additions and 1 deletions
|
|
@ -309,6 +309,10 @@ static CURLcode socket_open(struct Curl_easy *data,
|
||||||
{
|
{
|
||||||
char errbuf[STRERROR_LEN];
|
char errbuf[STRERROR_LEN];
|
||||||
|
|
||||||
|
#ifdef SOCK_CLOEXEC
|
||||||
|
addr->socktype |= SOCK_CLOEXEC;
|
||||||
|
#endif
|
||||||
|
|
||||||
DEBUGASSERT(data);
|
DEBUGASSERT(data);
|
||||||
DEBUGASSERT(data->conn);
|
DEBUGASSERT(data->conn);
|
||||||
if(data->set.fopensocket) {
|
if(data->set.fopensocket) {
|
||||||
|
|
@ -351,7 +355,7 @@ static CURLcode socket_open(struct Curl_easy *data,
|
||||||
}
|
}
|
||||||
#endif /* USE_SO_NOSIGPIPE */
|
#endif /* USE_SO_NOSIGPIPE */
|
||||||
|
|
||||||
#ifdef HAVE_FCNTL
|
#if defined(HAVE_FCNTL) && !defined(SOCK_CLOEXEC)
|
||||||
if(fcntl(*sockfd, F_SETFD, FD_CLOEXEC) < 0) {
|
if(fcntl(*sockfd, F_SETFD, FD_CLOEXEC) < 0) {
|
||||||
failf(data, "fcntl set CLOEXEC: %s",
|
failf(data, "fcntl set CLOEXEC: %s",
|
||||||
curlx_strerror(SOCKERRNO, errbuf, sizeof(errbuf)));
|
curlx_strerror(SOCKERRNO, errbuf, sizeof(errbuf)));
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue