]> xenbits.xensource.com Git - libvirt.git/commitdiff
testutils: Resolve Coverity issues
authorJohn Ferlan <jferlan@redhat.com>
Thu, 11 Jul 2013 11:22:20 +0000 (07:22 -0400)
committerJohn Ferlan <jferlan@redhat.com>
Thu, 11 Jul 2013 18:18:11 +0000 (14:18 -0400)
Recent changes uncovered a NEGATIVE_RETURNS in the return from sysconf()
when processing a for loop in virtTestCaptureProgramExecChild() in
testutils.c

Code review uncovered 3 other code paths with the same condition that
weren't found by Covirity, so fixed those as well.

src/lxc/lxc_container.c
src/util/vircommand.c
tests/commandhelper.c
tests/testutils.c

index 543e0d13c0c98e7f0e7977f559fb28b3fb01f8b0..7434264d8ee88e9b51f2ed212a40ff5e3f365678 100644 (file)
@@ -247,6 +247,11 @@ static int lxcContainerSetStdio(int control, int ttyfd, int handshakefd)
     /* Just in case someone forget to set FD_CLOEXEC, explicitly
      * close all FDs before executing the container */
     open_max = sysconf(_SC_OPEN_MAX);
+    if (open_max < 0) {
+        virReportSystemError(errno, "%s",
+                             _("sysconf(_SC_OPEN_MAX) failed"));
+        goto cleanup;
+    }
     for (fd = 0; fd < open_max; fd++)
         if (fd != ttyfd && fd != control && fd != handshakefd) {
             int tmpfd = fd;
index 3529f1a5d82a4631a234ac904fa3ca0c3abf791c..033b55b6ee8c66a193dc97ad6a32c273797a3113 100644 (file)
@@ -511,6 +511,11 @@ virExec(virCommandPtr cmd)
     }
 
     openmax = sysconf(_SC_OPEN_MAX);
+    if (openmax < 0) {
+        virReportSystemError(errno,  "%s",
+                             _("sysconf(_SC_OPEN_MAX) failed"));
+        goto fork_error;
+    }
     for (fd = 3; fd < openmax; fd++) {
         if (fd == childin || fd == childout || fd == childerr)
             continue;
index 0c5aa82d15d94fc16938c3409be0f444c930aef3..296fbbb3d1092449ec4ddd773a77b1bb6ffd69f2 100644 (file)
@@ -58,6 +58,7 @@ static int envsort(const void *a, const void *b) {
 
 int main(int argc, char **argv) {
     size_t i, n;
+    int open_max;
     char **origenv;
     char **newenv;
     char *cwd;
@@ -96,7 +97,10 @@ int main(int argc, char **argv) {
             fprintf(log, "ENV:%s\n", newenv[i]);
     }
 
-    for (i = 0; i < sysconf(_SC_OPEN_MAX); i++) {
+    open_max = sysconf(_SC_OPEN_MAX);
+    if (open_max < 0)
+        return EXIT_FAILURE;
+    for (i = 0; i < open_max; i++) {
         int f;
         int closed;
         if (i == fileno(log))
index ec0fe529e07e479e057963d850b2e7afc95676e0..2fdf7b8e7a691785287739fbad61679a2a3dcfcf 100644 (file)
@@ -281,6 +281,9 @@ void virtTestCaptureProgramExecChild(const char *const argv[],
         goto cleanup;
 
     open_max = sysconf(_SC_OPEN_MAX);
+    if (open_max < 0)
+        goto cleanup;
+
     for (i = 0; i < open_max; i++) {
         if (i != stdinfd &&
             i != pipefd) {