From 5e18531754ac43fee181064b6c6959b158fd93bc Mon Sep 17 00:00:00 2001 From: "Todd C. Miller" Date: Fri, 28 Feb 2014 15:04:36 -0700 Subject: [PATCH] Avoid a crash on Mac OS X 10.8 (at least) when we close libdispatch's fds out from under it before executing the command. Switch to just setting the close on exec flag instead. --HG-- branch : 1.7 --- closefrom.c | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/closefrom.c b/closefrom.c index d534d9d48..1438e9ef8 100644 --- a/closefrom.c +++ b/closefrom.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2004-2005, 2007, 2010 + * Copyright (c) 2004-2005, 2007, 2010, 2012-2013 * Todd C. Miller * * Permission to use, copy, modify, and distribute this software for any @@ -83,8 +83,14 @@ closefrom_fallback(lowfd) if (maxfd < 0) maxfd = OPEN_MAX; - for (fd = lowfd; fd < maxfd; fd++) + for (fd = lowfd; fd < maxfd; fd++) { +#ifdef __APPLE__ + /* Avoid potential libdispatch crash when we close its fds. */ + (void) fcntl((int) fd, F_SETFD, FD_CLOEXEC); +#else (void) close((int) fd); +#endif + } } /* @@ -129,8 +135,14 @@ closefrom(lowfd) while ((dent = readdir(dirp)) != NULL) { fd = strtol(dent->d_name, &endp, 10); if (dent->d_name != endp && *endp == '\0' && - fd >= 0 && fd < INT_MAX && fd >= lowfd && fd != dirfd(dirp)) + fd >= 0 && fd < INT_MAX && fd >= lowfd && fd != dirfd(dirp)) { +# ifdef __APPLE__ + /* Avoid potential libdispatch crash when we close its fds. */ + (void) fcntl((int) fd, F_SETFD, FD_CLOEXEC); +# else (void) close((int) fd); +# endif + } } (void) closedir(dirp); } else -- 2.40.0