[libvirt] [PATCH 3/4] util: Avoid possible error in virCommandMassClose

John Ferlan posted 4 patches 5 years, 4 months ago
[libvirt] [PATCH 3/4] util: Avoid possible error in virCommandMassClose
Posted by John Ferlan 5 years, 4 months ago
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>
---
 src/util/vircommand.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/util/vircommand.c b/src/util/vircommand.c
index 4501c96bbf..cedbd01446 100644
--- a/src/util/vircommand.c
+++ b/src/util/vircommand.c
@@ -487,7 +487,7 @@ virCommandMassClose(virCommandPtr cmd,
      * Therefore we can safely allocate memory here (and transitively call
      * opendir/readdir) without a deadlock. */
 
-    if (!(fds = virBitmapNew(openmax)))
+    if (openmax < 0 || !(fds = virBitmapNew(openmax)))
         return -1;
 
 # ifdef __linux__
-- 
2.20.1

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH 3/4] util: Avoid possible error in virCommandMassClose
Posted by Peter Krempa 5 years, 4 months ago
On Tue, Jul 23, 2019 at 09:58:10 -0400, John Ferlan wrote:
> 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>
> ---
>  src/util/vircommand.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/src/util/vircommand.c b/src/util/vircommand.c
> index 4501c96bbf..cedbd01446 100644
> --- a/src/util/vircommand.c
> +++ b/src/util/vircommand.c
> @@ -487,7 +487,7 @@ virCommandMassClose(virCommandPtr cmd,
>       * Therefore we can safely allocate memory here (and transitively call
>       * opendir/readdir) without a deadlock. */
>  
> -    if (!(fds = virBitmapNew(openmax)))
> +    if (openmax < 0 || !(fds = virBitmapNew(openmax)))
>          return -1;

This would not report an libvirt error, but all other code paths do so.

>  
>  # ifdef __linux__
> -- 
> 2.20.1
> 
> --
> libvir-list mailing list
> libvir-list@redhat.com
> https://www.redhat.com/mailman/listinfo/libvir-list
--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list