Only use closefrom_fallback() if no better method exists.

The previous logic was too fragile.
This commit is contained in:
Todd C. Miller
2018-11-08 15:17:39 -07:00
parent 733669ec38
commit 537a2f9773

View File

@@ -43,15 +43,11 @@
# define _POSIX_OPEN_MAX 20
#endif
#if defined(HAVE_FCNTL_CLOSEM) && !defined(HAVE_DIRFD)
# define sudo_closefrom closefrom_fallback
#endif
/*
* Close all file descriptors greater than or equal to lowfd.
* This is the expensive (fallback) method.
*/
void
static void
closefrom_fallback(int lowfd)
{
long fd, maxfd;
@@ -131,5 +127,12 @@ sudo_closefrom(int lowfd)
} else
closefrom_fallback(lowfd);
}
#else
void
sudo_closefrom(int lowfd)
{
closefrom_fallback(lowfd);
}
#endif /* HAVE_FCNTL_CLOSEM */
#endif /* HAVE_CLOSEFROM */