Skip to content

Commit a9f5e18

Browse files
committed
Check for dup2() errors and avoid FD leak
Trivial change.
1 parent a9d11c0 commit a9f5e18

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

daemon/qrexec-daemon.c

+4-2
Original file line numberDiff line numberDiff line change
@@ -360,8 +360,10 @@ static void init(int xid, bool opt_direct)
360360
exit(1);
361361
}
362362

363-
dup2(logfd, 1);
364-
dup2(logfd, 2);
363+
if (dup2(logfd, 1) != 1 || dup2(logfd, 2) != 2)
364+
err(1, "dup2()");
365+
if (logfd > 2)
366+
close(logfd);
365367

366368
if (setsid() < 0) {
367369
PERROR("setsid()");

0 commit comments

Comments
 (0)