]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
util: Avoid possible error in virCommandMassClose
authorJohn Ferlan <jferlan@redhat.com>
Tue, 23 Jul 2019 12:12:48 +0000 (08:12 -0400)
committerJohn Ferlan <jferlan@redhat.com>
Tue, 23 Jul 2019 14:56:22 +0000 (10:56 -0400)
Avoid the chance that sysconf(_SC_OPEN_MAX) returns -1 and thus
would cause virBitmapNew would attempt to allocate a very large
bitmap.

Found by Coverity

Signed-off-by: John Ferlan <jferlan@redhat.com>
ACKed-by: Peter Krempa <pkrempa@redhat.com>
src/util/vircommand.c

index 4501c96bbf2733c32d44eda050cfab6345ab9689..e10ca3eb7c16ae6147682fe409814ba6a0ac10e5 100644 (file)
@@ -487,6 +487,11 @@ virCommandMassClose(virCommandPtr cmd,
      * Therefore we can safely allocate memory here (and transitively call
      * opendir/readdir) without a deadlock. */
 
+    if (openmax < 0) {
+        virReportSystemError(errno, "%s", _("sysconf(_SC_OPEN_MAX) failed"));
+        return -1;
+    }
+
     if (!(fds = virBitmapNew(openmax)))
         return -1;