GNU bug report logs -
#61095
possible misuse of posix_spawn API on non-linux OSes
Previous Next
Reported by: Omar Polo <op <at> omarpolo.com>
Date: Fri, 27 Jan 2023 11:53:01 UTC
Severity: normal
Tags: patch
Merged with 61079
Done: Ludovic Courtès <ludo <at> gnu.org>
Bug is archived. No further changes may be made.
Full log
Message #8 received at 61095 <at> debbugs.gnu.org (full text, mbox):
Actually I can avoid the EBADF by checking that the fd is 'live' with
something like fstat:
[[[
Index: libguile/posix.c
--- libguile/posix.c.orig
+++ libguile/posix.c
@@ -1325,8 +1325,12 @@ SCM_DEFINE (scm_fork, "primitive-fork", 0, 0, 0,
static void
close_inherited_fds_slow (posix_spawn_file_actions_t *actions, int max_fd)
{
- while (--max_fd > 2)
- posix_spawn_file_actions_addclose (actions, max_fd);
+ struct stat sb;
+ max_fd = getdtablecount();
+ while (--max_fd > 2) {
+ if (fstat(max_fd, &sb) != -1)
+ posix_spawn_file_actions_addclose (actions, max_fd);
+ }
}
static void
]]]
The regress passes and while this workaround may be temporarly
acceptable I -personally- don't like it much. There's a reason guile
can't set CLOEXEC for all the file descriptors > 2 obtained via open,
socket, pipe, ... like perl -for example- does?
This bug report was last modified 2 years and 105 days ago.
Previous Next
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.