From ec255e352eb04b033b8cb36085a937a53a1401b4 Mon Sep 17 00:00:00 2001 From: Scott Mcdermott Date: Tue, 10 Sep 2024 03:05:21 -0700 Subject: [PATCH] main: close the tmp fd we used to duplicate /dev/null for stdin We didn't want to leak the initial startup stdin -- which is the tty where X started -- to all child procs, so we opened /dev/null and duplicated it onto fd 1. but then we forgot to close the temporary fd so it leaks to child procs. --- sdorfehs.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/sdorfehs.c b/sdorfehs.c index bb3bdaa..ccb1bd3 100644 --- a/sdorfehs.c +++ b/sdorfehs.c @@ -232,7 +232,7 @@ init_defaults(void) int main(int argc, char *argv[]) { - int c; + int c, fd; char **cmd = NULL; int cmd_count = 0; char *display = NULL; @@ -287,7 +287,9 @@ main(int argc, char *argv[]) set_close_on_exec(ConnectionNumber(dpy)); /* forked commands should not get X console tty as their stdin */ - dup2(open("/dev/null", O_RDONLY), STDIN_FILENO); + fd = open("/dev/null", O_RDONLY); + dup2(fd, STDIN_FILENO); + close(fd); /* Set our own specific Atoms. */ rp_selection = XInternAtom(dpy, "RP_SELECTION", False);