From 26cff8bcb5d9b331085873467b90daa6c5eafaac Mon Sep 17 00:00:00 2001 From: "Todd C. Miller" Date: Tue, 14 Jan 2014 14:22:04 -0700 Subject: [PATCH] When restoring fds traverse list from high -> low, not low -> high to avoid implicitly closing an fd we want to relocate. --- src/preserve_fds.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/preserve_fds.c b/src/preserve_fds.c index e1ed57038..4cc5d2edf 100644 --- a/src/preserve_fds.c +++ b/src/preserve_fds.c @@ -166,7 +166,7 @@ closefrom_except(int startfd, struct preserved_fd_list *pfds) closefrom(startfd); /* Restore preserved fds and set flags. */ - TAILQ_FOREACH(pfd, pfds, entries) { + TAILQ_FOREACH_REVERSE(pfd, pfds, preserved_fd_list, entries) { if (pfd->lowfd != pfd->highfd) { if (dup2(pfd->lowfd, pfd->highfd) == -1) { sudo_debug_printf(SUDO_DEBUG_ERROR|SUDO_DEBUG_LINENO,