From 048bb5bd4950b9cb5368ed93d273f0f36e439122 Mon Sep 17 00:00:00 2001 From: Chris Dunlap Date: Tue, 1 Mar 2016 12:23:55 -0800 Subject: Ensure zed _finish_daemonize() leaves fds 0-2 open In zed's _finish_daemonize(), /dev/null is open()d onto a temporary file descriptor which is then dup()d onto stdin, stdout, and stderr. But if file descriptors 0, 1, or 2 are not already open at the start of this function, then the temporary file descriptor will fall within this range and be inadvertently closed when the function cleans up. This commit adds a check to prevent inadvertently closing this (presumably temporary) file descriptor when it shouldn't. Signed-off-by: Chris Dunlap Signed-off-by: Brian Behlendorf Closes #4384 --- cmd/zed/zed.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'cmd/zed/zed.c') diff --git a/cmd/zed/zed.c b/cmd/zed/zed.c index f85668fea..55ab68cd0 100644 --- a/cmd/zed/zed.c +++ b/cmd/zed/zed.c @@ -199,7 +199,7 @@ _finish_daemonize(void) zed_log_die("Failed to dup /dev/null onto stderr: %s", strerror(errno)); - if (close(devnull) < 0) + if ((devnull > STDERR_FILENO) && (close(devnull) < 0)) zed_log_die("Failed to close /dev/null: %s", strerror(errno)); /* Notify parent that daemonization is complete. */ -- cgit v1.2.3