From 7a9773a303458920a1dfc49e1406e254935ad42d Mon Sep 17 00:00:00 2001 From: Jan Grulich Date: Mon, 8 Jan 2024 13:19:01 +0100 Subject: [PATCH] Xvnc: do not use dup2() to create a file descriptor for -inetd option Use dup() instead to get an available file descriptor to avoid hijacking already existing descriptor. Fixes #1709 --- unix/xserver/hw/vnc/xvnc.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/unix/xserver/hw/vnc/xvnc.c b/unix/xserver/hw/vnc/xvnc.c index f8141959..e13d09fd 100644 --- a/unix/xserver/hw/vnc/xvnc.c +++ b/unix/xserver/hw/vnc/xvnc.c @@ -366,8 +366,10 @@ ddxProcessArgument(int argc, char *argv[], int i) if (strcmp(argv[i], "-inetd") == 0) { int nullfd; - dup2(0, 3); - vncInetdSock = 3; + if ((vncInetdSock = dup(0)) == -1) + FatalError + ("Xvnc error: failed to allocate a new file descriptor for -inetd: %s\n", strerror(errno)); + /* Avoid xserver >= 1.19's epoll-fd becoming fd 2 / stderr only to be replaced by /dev/null by OsInit() because the pollfd is not -- 2.39.5