2025-05-28 11:24:12 +00:00
|
|
|
Open library file descriptors with O_CLOEXEC
|
|
|
|
|
This patch is non-portable, it needs linux 2.6.23 and glibc 2.7
|
|
|
|
|
or later, different combinations (old linux, new glibc and vice-versa)
|
|
|
|
|
will result in a crash.
|
|
|
|
|
|
|
|
|
|
To make it portable you have to test O_CLOEXEC support at *runtime*
|
|
|
|
|
compile time is not enough.
|
|
|
|
|
|
|
|
|
|
|
2026-01-20 13:52:52 +01:00
|
|
|
Index: curl-8.18.0/lib/file.c
|
2025-05-28 11:24:12 +00:00
|
|
|
===================================================================
|
2026-01-20 13:52:52 +01:00
|
|
|
--- curl-8.18.0.orig/lib/file.c
|
|
|
|
|
+++ curl-8.18.0/lib/file.c
|
|
|
|
|
@@ -258,7 +258,7 @@ static CURLcode file_connect(struct Curl
|
2025-05-28 11:24:12 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
#else
|
2026-01-20 13:52:52 +01:00
|
|
|
- fd = curlx_open(real_path, O_RDONLY);
|
|
|
|
|
+ fd = curlx_open(real_path, O_RDONLY|O_CLOEXEC);
|
2025-05-28 11:24:12 +00:00
|
|
|
file->path = real_path;
|
|
|
|
|
#endif
|
|
|
|
|
#endif
|
2026-01-20 13:52:52 +01:00
|
|
|
@@ -339,9 +339,9 @@ static CURLcode file_upload(struct Curl_
|
|
|
|
|
data->set.new_file_perms & (_S_IREAD | _S_IWRITE));
|
|
|
|
|
#elif (defined(ANDROID) || defined(__ANDROID__)) && \
|
2025-10-20 13:16:33 +02:00
|
|
|
(defined(__i386__) || defined(__arm__))
|
2026-01-20 13:52:52 +01:00
|
|
|
- fd = curlx_open(file->path, mode, (mode_t)data->set.new_file_perms);
|
|
|
|
|
+ fd = curlx_open(file->path, mode|O_CLOEXEC, (mode_t)data->set.new_file_perms);
|
2025-05-28 11:24:12 +00:00
|
|
|
#else
|
2026-01-20 13:52:52 +01:00
|
|
|
- fd = curlx_open(file->path, mode, data->set.new_file_perms);
|
|
|
|
|
+ fd = curlx_open(file->path, mode|O_CLOEXEC, data->set.new_file_perms);
|
2025-05-28 11:24:12 +00:00
|
|
|
#endif
|
|
|
|
|
if(fd < 0) {
|
|
|
|
|
failf(data, "cannot open %s for writing", file->path);
|
2026-01-20 13:52:52 +01:00
|
|
|
Index: curl-8.18.0/lib/if2ip.c
|
2025-05-28 11:24:12 +00:00
|
|
|
===================================================================
|
2026-01-20 13:52:52 +01:00
|
|
|
--- curl-8.18.0.orig/lib/if2ip.c
|
|
|
|
|
+++ curl-8.18.0/lib/if2ip.c
|
|
|
|
|
@@ -202,7 +202,7 @@ if2ip_result_t Curl_if2ip(int af,
|
2025-05-28 11:24:12 +00:00
|
|
|
if(len >= sizeof(req.ifr_name))
|
|
|
|
|
return IF2IP_NOT_FOUND;
|
|
|
|
|
|
2026-01-20 13:52:52 +01:00
|
|
|
- dummy = CURL_SOCKET(AF_INET, SOCK_STREAM, 0);
|
|
|
|
|
+ dummy = CURL_SOCKET(AF_INET, SOCK_STREAM|SOCK_CLOEXEC, 0);
|
2025-05-28 11:24:12 +00:00
|
|
|
if(CURL_SOCKET_BAD == dummy)
|
|
|
|
|
return IF2IP_NOT_FOUND;
|
|
|
|
|
|
2026-01-20 13:52:52 +01:00
|
|
|
Index: curl-8.18.0/configure.ac
|
2025-05-28 11:24:12 +00:00
|
|
|
===================================================================
|
2026-01-20 13:52:52 +01:00
|
|
|
--- curl-8.18.0.orig/configure.ac
|
|
|
|
|
+++ curl-8.18.0/configure.ac
|
|
|
|
|
@@ -504,6 +504,8 @@ AC_DEFINE_UNQUOTED(CURL_OS, "${host}", [
|
2025-05-28 11:24:12 +00:00
|
|
|
# Silence warning: ar: 'u' modifier ignored since 'D' is the default
|
|
|
|
|
AC_SUBST(AR_FLAGS, [cr])
|
|
|
|
|
|
|
|
|
|
+AC_USE_SYSTEM_EXTENSIONS
|
|
|
|
|
+
|
|
|
|
|
dnl This defines _ALL_SOURCE for AIX
|
|
|
|
|
CURL_CHECK_AIX_ALL_SOURCE
|
|
|
|
|
|
2026-01-20 13:52:52 +01:00
|
|
|
Index: curl-8.18.0/lib/hostip.c
|
2025-05-28 11:24:12 +00:00
|
|
|
===================================================================
|
2026-01-20 13:52:52 +01:00
|
|
|
--- curl-8.18.0.orig/lib/hostip.c
|
|
|
|
|
+++ curl-8.18.0/lib/hostip.c
|
|
|
|
|
@@ -43,6 +43,7 @@
|
|
|
|
|
#include <setjmp.h> /* for sigjmp_buf, sigsetjmp() */
|
2025-05-28 11:24:12 +00:00
|
|
|
#include <signal.h>
|
|
|
|
|
|
|
|
|
|
+#include <fcntl.h>
|
|
|
|
|
#include "urldata.h"
|
2026-01-20 13:52:52 +01:00
|
|
|
#include "curl_trc.h"
|
2025-05-28 11:24:12 +00:00
|
|
|
#include "connect.h"
|
2026-01-20 13:52:52 +01:00
|
|
|
@@ -689,7 +690,7 @@ bool Curl_ipv6works(struct Curl_easy *da
|
2025-05-28 11:24:12 +00:00
|
|
|
else {
|
|
|
|
|
int ipv6_works = -1;
|
|
|
|
|
/* probe to see if we have a working IPv6 stack */
|
2026-01-20 13:52:52 +01:00
|
|
|
- curl_socket_t s = CURL_SOCKET(PF_INET6, SOCK_DGRAM, 0);
|
|
|
|
|
+ curl_socket_t s = CURL_SOCKET(PF_INET6, SOCK_DGRAM|SOCK_CLOEXEC, 0);
|
2025-05-28 11:24:12 +00:00
|
|
|
if(s == CURL_SOCKET_BAD)
|
|
|
|
|
/* an IPv6 address was requested but we cannot get/use one */
|
|
|
|
|
ipv6_works = 0;
|
2026-01-20 13:52:52 +01:00
|
|
|
Index: curl-8.18.0/lib/cf-socket.c
|
2025-05-28 11:24:12 +00:00
|
|
|
===================================================================
|
2026-01-20 13:52:52 +01:00
|
|
|
--- curl-8.18.0.orig/lib/cf-socket.c
|
|
|
|
|
+++ curl-8.18.0/lib/cf-socket.c
|
|
|
|
|
@@ -345,7 +345,8 @@ static CURLcode socket_open(struct Curl_
|
2025-05-28 11:24:12 +00:00
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
/* opensocket callback not set, so simply create the socket now */
|
2026-01-20 13:52:52 +01:00
|
|
|
- *sockfd = CURL_SOCKET(addr->family, addr->socktype, addr->protocol);
|
|
|
|
|
+ *sockfd = CURL_SOCKET(addr->family, addr->socktype|SOCK_CLOEXEC,
|
|
|
|
|
+ addr->protocol);
|
|
|
|
|
if((*sockfd == CURL_SOCKET_BAD) && (SOCKERRNO == SOCKENOMEM))
|
|
|
|
|
return CURLE_OUT_OF_MEMORY;
|
2025-05-28 11:24:12 +00:00
|
|
|
}
|