[libvirt] [PATCH] lxc_controller.c: don't ignore failed "accept"

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



coverity complained (rightly) about the risk of closing a negative
file descriptor.  However, the real problem was the missing test
for a failed "accept" call.  I'm not 100% sure that a failed
accept call deserves to provoke a "goto cleanup", but doing that
is consistent with what the nearby code does upon epoll_ctl failure.

>From 8bfd81f0a8a9cb3fd9b575e9c2f5ab9969a2910f Mon Sep 17 00:00:00 2001
From: Jim Meyering <meyering@xxxxxxxxxx>
Date: Tue, 2 Feb 2010 11:55:19 +0100
Subject: [PATCH] lxc_controller.c: don't ignore failed "accept"

* src/lxc/lxc_controller.c (lxcControllerMain): A failed accept could
lead to passing a negative file descriptor to various other functions,
which would in turn report EBADF, rather that whatever error prompted
the initial failure.
---
 src/lxc/lxc_controller.c |    5 +++++
 1 files changed, 5 insertions(+), 0 deletions(-)

diff --git a/src/lxc/lxc_controller.c b/src/lxc/lxc_controller.c
index 6304815..682f874 100644
--- a/src/lxc/lxc_controller.c
+++ b/src/lxc/lxc_controller.c
@@ -349,6 +349,11 @@ static int lxcControllerMain(int monitor,
         if (numEvents > 0) {
             if (epollEvent.data.fd == monitor) {
                 int fd = accept(monitor, NULL, 0);
+                if (fd < 0) {
+                    virReportSystemError(NULL, errno, "%s",
+                                         _("accept(monitor,...) failed"));
+                    goto cleanup;
+                }
                 if (client != -1) { /* Already connected, so kick new one out */
                     close(fd);
                     continue;
--
1.7.0.rc1.149.g0b0b7

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list

[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]