[PATCH v2 python 2/2] add check for pycpumap length

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



If we pass large(more than cpunum) cpu mask to any libvirt_virDomainPin*
function, it could leads to crash. So we have to check tuple size in
virPyCpuMapToChar and ignore extra tuple members.

Signed-off-by: Konstantin Neumoin <kneumoin@xxxxxxxxxxxxx>
---
 libvirt-utils.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/libvirt-utils.c b/libvirt-utils.c
index aaf4bea..3fc0fdd 100644
--- a/libvirt-utils.c
+++ b/libvirt-utils.c
@@ -589,7 +589,8 @@ virPyDictToTypedParams(PyObject *dict,
 
 
 /* virPyCpuMapToChar
- * @cpunum: the number of cpus
+ * @cpunum: the number of cpus, only this first elements make sense,
+ * so others will be ignored(filled by zeros).
  * @pycpumap: source Py cpu map
  * @cpumapptr: destination cpu map
  * @cpumaplen: destination cpu map length
@@ -604,7 +605,7 @@ virPyCpuMapToChar(int cpunum,
                   unsigned char **cpumapptr,
                   int *cpumaplen)
 {
-    int tuple_size;
+    int tuple_size, rel_cpumaplen;
     size_t i;
     int i_retval = -1;
     *cpumapptr = NULL;
@@ -624,7 +625,9 @@ virPyCpuMapToChar(int cpunum,
         goto exit;
     }
 
-    for (i = 0; i < tuple_size; i++) {
+    rel_cpumaplen = MIN(cpunum, tuple_size);
+
+    for (i = 0; i < rel_cpumaplen; i++) {
         PyObject *flag = PyTuple_GetItem(pycpumap, i);
         bool b;
 
-- 
2.5.5

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list



[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]