render / rpms / libvirt

Forked from rpms/libvirt 9 months ago
Clone
9119d9
From fb5f9100a7ca6e8d63b1ec2b1c5d3ae12f146d71 Mon Sep 17 00:00:00 2001
9119d9
Message-Id: <fb5f9100a7ca6e8d63b1ec2b1c5d3ae12f146d71@dist-git>
9119d9
From: John Ferlan <jferlan@redhat.com>
9119d9
Date: Mon, 15 Sep 2014 15:13:56 -0400
9119d9
Subject: [PATCH] daemon: Resolve Coverity RESOURCE_LEAK
9119d9
9119d9
https://bugzilla.redhat.com/show_bug.cgi?id=1141209
9119d9
9119d9
With eblake's help - adjust the checks for stdinfd/stdoutfd to ensure the
9119d9
values are within the range we expect; otherwise the dup2()'s and subsequent
9119d9
VIR_CLOSE() calls cause Coverity to believe there's a resource leak.
9119d9
9119d9
Signed-off-by: John Ferlan <jferlan@redhat.com>
9119d9
(cherry picked from commit c77ac79d6b5a6758f3a980d2edfd0abda9aa7d3e)
9119d9
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
9119d9
---
9119d9
 daemon/libvirtd.c | 8 ++++----
9119d9
 1 file changed, 4 insertions(+), 4 deletions(-)
9119d9
9119d9
diff --git a/daemon/libvirtd.c b/daemon/libvirtd.c
9119d9
index 0503cd0..05ee50e 100644
9119d9
--- a/daemon/libvirtd.c
9119d9
+++ b/daemon/libvirtd.c
9119d9
@@ -163,9 +163,9 @@ static int daemonForkIntoBackground(const char *argv0)
9119d9
 
9119d9
             VIR_FORCE_CLOSE(statuspipe[0]);
9119d9
 
9119d9
-            if ((stdinfd = open("/dev/null", O_RDONLY)) < 0)
9119d9
+            if ((stdinfd = open("/dev/null", O_RDONLY)) <= STDERR_FILENO)
9119d9
                 goto cleanup;
9119d9
-            if ((stdoutfd = open("/dev/null", O_WRONLY)) < 0)
9119d9
+            if ((stdoutfd = open("/dev/null", O_WRONLY)) <= STDERR_FILENO)
9119d9
                 goto cleanup;
9119d9
             if (dup2(stdinfd, STDIN_FILENO) != STDIN_FILENO)
9119d9
                 goto cleanup;
9119d9
@@ -173,9 +173,9 @@ static int daemonForkIntoBackground(const char *argv0)
9119d9
                 goto cleanup;
9119d9
             if (dup2(stdoutfd, STDERR_FILENO) != STDERR_FILENO)
9119d9
                 goto cleanup;
9119d9
-            if (stdinfd > STDERR_FILENO && VIR_CLOSE(stdinfd) < 0)
9119d9
+            if (VIR_CLOSE(stdinfd) < 0)
9119d9
                 goto cleanup;
9119d9
-            if (stdoutfd > STDERR_FILENO && VIR_CLOSE(stdoutfd) < 0)
9119d9
+            if (VIR_CLOSE(stdoutfd) < 0)
9119d9
                 goto cleanup;
9119d9
 
9119d9
             if (setsid() < 0)
9119d9
-- 
9119d9
2.1.0
9119d9