Skip to content

Commit

Permalink
main: close the tmp fd we used to duplicate /dev/null for stdin
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
smemsh authored and jcs committed Sep 10, 2024
1 parent 50c0635 commit ee2a18f
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions sdorfehs.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit ee2a18f

Please sign in to comment.