[PATCH v3 python 2/2] don't overrun buffer when converting cpumap

[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
virPyCpumapConvert and ignore extra tuple members.

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

diff --git a/libvirt-utils.c b/libvirt-utils.c
index 09cc1c3..ac3606b 100644
--- a/libvirt-utils.c
+++ b/libvirt-utils.c
@@ -623,7 +623,15 @@ virPyCpumapConvert(int cpunum,
         return -1;
     }
 
-    for (i = 0; i < tuple_size; i++) {
+    /* Not presented elements of the tuple will be filled by zeros.
+     * Only first "cpunum" elements make sense, so the rest
+     * of the bits from the tuple will be ignored. */
+    for (i = 0; i < cpunum; i++) {
+        if (i >= tuple_size) {
+            VIR_UNUSE_CPU(*cpumapptr, i);
+            continue;
+        }
+
         PyObject *flag = PyTuple_GetItem(pycpumap, i);
         bool b;
 
@@ -638,8 +646,5 @@ virPyCpumapConvert(int cpunum,
             VIR_UNUSE_CPU(*cpumapptr, i);
     }
 
-    for (; i < cpunum; i++)
-        VIR_UNUSE_CPU(*cpumapptr, i);
-
     return 0;
 }
-- 
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]