From 981f322f23cbd72ff9a7eece11457ddaf25e70f6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simon=20=C5=BDlender?= Date: Tue, 14 Jan 2025 10:55:36 +0100 Subject: [PATCH] curl: apply eventfd free patch --- .../cu/curlMinimal/fix-eventfd-free.patch | 33 +++++++++++++++++++ pkgs/by-name/cu/curlMinimal/package.nix | 5 +++ 2 files changed, 38 insertions(+) create mode 100644 pkgs/by-name/cu/curlMinimal/fix-eventfd-free.patch diff --git a/pkgs/by-name/cu/curlMinimal/fix-eventfd-free.patch b/pkgs/by-name/cu/curlMinimal/fix-eventfd-free.patch new file mode 100644 index 0000000000000..5b0979fd4cbdc --- /dev/null +++ b/pkgs/by-name/cu/curlMinimal/fix-eventfd-free.patch @@ -0,0 +1,33 @@ +From ff5091aa9f73802e894b1cbdf24ab84e103200e2 Mon Sep 17 00:00:00 2001 +From: Andy Pan +Date: Thu, 12 Dec 2024 12:48:56 +0000 +Subject: [PATCH] async-thread: avoid closing eventfd twice + +When employing eventfd for socketpair, there is only one file +descriptor. Closing that fd twice might result in fd corruption. +Thus, we should avoid closing the eventfd twice, following the +pattern in lib/multi.c. + +Fixes #15725 +Closes #15727 +Reported-by: Christian Heusel +--- + lib/asyn-thread.c | 2 ++ + 1 file changed, 2 insertions(+) + +diff --git a/lib/asyn-thread.c b/lib/asyn-thread.c +index a58e4b790494..32d496b107cb 100644 +--- a/lib/asyn-thread.c ++++ b/lib/asyn-thread.c +@@ -195,9 +195,11 @@ void destroy_thread_sync_data(struct thread_sync_data *tsd) + * close one end of the socket pair (may be done in resolver thread); + * the other end (for reading) is always closed in the parent thread. + */ ++#ifndef USE_EVENTFD + if(tsd->sock_pair[1] != CURL_SOCKET_BAD) { + wakeup_close(tsd->sock_pair[1]); + } ++#endif + #endif + memset(tsd, 0, sizeof(*tsd)); + } diff --git a/pkgs/by-name/cu/curlMinimal/package.nix b/pkgs/by-name/cu/curlMinimal/package.nix index 2716d08839a41..2f676cbafe58c 100644 --- a/pkgs/by-name/cu/curlMinimal/package.nix +++ b/pkgs/by-name/cu/curlMinimal/package.nix @@ -59,6 +59,11 @@ stdenv.mkDerivation (finalAttrs: { hash = "sha256-x8p9tIsJCXQ+rvNCUNoCwZvGHU8dzt1mA/EJQJU2q1Y="; }; + patches = [ + # https://github.com/curl/curl/issues/15725 + ./fix-eventfd-free.patch + ]; + # this could be accomplished by updateAutotoolsGnuConfigScriptsHook, but that causes infinite recursion # necessary for FreeBSD code path in configure postPatch = ''