render / rpms / libvirt

Forked from rpms/libvirt 10 months ago
Clone
Blob Blame History Raw
From abf1be5d4639ca4b58d56633129a7cf1389b97f3 Mon Sep 17 00:00:00 2001
Message-Id: <abf1be5d4639ca4b58d56633129a7cf1389b97f3@dist-git>
From: John Ferlan <jferlan@redhat.com>
Date: Tue, 30 Jul 2019 16:04:52 +0200
Subject: [PATCH] util: Avoid possible error in virCommandMassClose
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

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>
(cherry picked from commit 6ae4f4a4ceb123417b732e869d53099983ae8d3f)

Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1721434

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Message-Id: <e17edd9e1f50630c019ec7206a0f15cd8c3e474a.1564495366.git.mprivozn@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
---
 src/util/vircommand.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/src/util/vircommand.c b/src/util/vircommand.c
index dfc7e5428b..c53e3f47db 100644
--- a/src/util/vircommand.c
+++ b/src/util/vircommand.c
@@ -560,6 +560,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;
 
-- 
2.22.0