From 6ae4f4a4ceb123417b732e869d53099983ae8d3f Mon Sep 17 00:00:00 2001 From: John Ferlan Date: Tue, 23 Jul 2019 08:12:48 -0400 Subject: [PATCH] util: Avoid possible error in virCommandMassClose 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 --- src/util/vircommand.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/util/vircommand.c b/src/util/vircommand.c index 4501c96bbf..e10ca3eb7c 100644 --- a/src/util/vircommand.c +++ b/src/util/vircommand.c @@ -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; -- GitLab