From: Leon Timmermans <fawaka@gmail.com>
Date: Mon, 9 Jun 2025 23:05:39 +0200
Subject: Use PerlLIO_dup_cloexec in Perl_dirp_dup to set O_CLOEXEC

dup doesn't mark the new descriptor as close-on-exec, which can lead to
a descriptor leaking to the new process.

(cherry picked from commit d6f09a896842e5288af5d3817756b67a919ad7ad)

Origin: upstream, https://github.com/Perl/perl5/commit/08dffa08a0a3822d9eaae5bd7aea9c3a5b67a3f3
Bug: https://github.com/Perl/perl5/issues/23010
Bug-Debian: https://bugs.debian.org/1098226
---
 sv.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/sv.c b/sv.c
index d2661be..f051550 100644
--- a/sv.c
+++ b/sv.c
@@ -14028,7 +14028,7 @@ Perl_dirp_dup(pTHX_ DIR *const dp, CLONE_PARAMS *const param)
 
     PERL_UNUSED_ARG(param);
 
-    ret = fdopendir(dup(my_dirfd(dp)));
+    ret = fdopendir(PerlLIO_dup_cloexec(my_dirfd(dp)));
 
 #elif defined(WIN32)
     ret = win32_dirp_dup(dp, param);
