Skip to content

Commit a5de843

Browse files
committed
Don't close file descriptor 0
Closing a standard FD is a bad idea, as it will be reused by subsequent system calls that create file descriptors. Point FD 0 at /dev/null instead.
1 parent a9aa1c5 commit a5de843

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

daemon/qrexec-daemon.c

+12-1
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,6 @@ static void init(int xid)
338338
}
339339
}
340340

341-
close(0);
342341

343342
if (chdir(socket_dir) < 0) {
344343
PERROR("chdir %s failed", socket_dir);
@@ -1572,6 +1571,18 @@ int main(int argc, char **argv)
15721571
int i, opt;
15731572
sigset_t selectmask;
15741573

1574+
{
1575+
int null_fd = open("/dev/null", O_RDONLY|O_NOCTTY);
1576+
if (null_fd < 0)
1577+
err(1, "open(%s)", "/dev/null");
1578+
if (null_fd > 0) {
1579+
if (dup2(null_fd, 0) != 0)
1580+
err(1, "dup2(%d, 0)", null_fd);
1581+
if (null_fd > 2 && close(null_fd) != 0)
1582+
err(1, "close(%d)", null_fd);
1583+
}
1584+
}
1585+
15751586
setup_logging("qrexec-daemon");
15761587

15771588
while ((opt=getopt_long(argc, argv, "hqp:D", longopts, NULL)) != -1) {

0 commit comments

Comments
 (0)