From abf1be5d4639ca4b58d56633129a7cf1389b97f3 Mon Sep 17 00:00:00 2001 Message-Id: From: John Ferlan 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 ACKed-by: Peter Krempa (cherry picked from commit 6ae4f4a4ceb123417b732e869d53099983ae8d3f) Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1721434 Signed-off-by: Michal Privoznik Message-Id: Reviewed-by: Ján Tomko --- 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