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

Konstantin Neumoin kneumoin at virtuozzo.com
Thu Nov 3 17:05:52 UTC 2016


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 at virtuozzo.com>
---
 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




More information about the libvir-list mailing list