[libvirt] [PATCH python 1/1] fix crash in libvirt_virDomainPin*

If we pass large(more than cpunum) cpu mask to any libvirt_virDomainPin* methods, it could leads to crash. So we have to check tuple size and ignore extra tuple members. Signed-off-by: Konstantin Neumoin <kneumoin@virtuozzo.com> --- libvirt-override.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/libvirt-override.c b/libvirt-override.c index fa3e2ca..83b760b 100644 --- a/libvirt-override.c +++ b/libvirt-override.c @@ -1327,7 +1327,7 @@ libvirt_virDomainPinVcpu(PyObject *self ATTRIBUTE_UNUSED, if (VIR_ALLOC_N(cpumap, cpumaplen) < 0) return PyErr_NoMemory(); - for (i = 0; i < tuple_size; i++) { + for (i = 0; i < MIN(cpunum, tuple_size); i++) { PyObject *flag = PyTuple_GetItem(pycpumap, i); bool b; @@ -1392,7 +1392,7 @@ libvirt_virDomainPinVcpuFlags(PyObject *self ATTRIBUTE_UNUSED, if (VIR_ALLOC_N(cpumap, cpumaplen) < 0) return PyErr_NoMemory(); - for (i = 0; i < tuple_size; i++) { + for (i = 0; i < MIN(cpunum, tuple_size); i++) { PyObject *flag = PyTuple_GetItem(pycpumap, i); bool b; @@ -1532,7 +1532,7 @@ libvirt_virDomainPinEmulator(PyObject *self ATTRIBUTE_UNUSED, if (VIR_ALLOC_N(cpumap, cpumaplen) < 0) return PyErr_NoMemory(); - for (i = 0; i < tuple_size; i++) { + for (i = 0; i < MIN(cpunum, tuple_size); i++) { PyObject *flag = PyTuple_GetItem(pycpumap, i); bool b; @@ -1738,7 +1738,7 @@ libvirt_virDomainPinIOThread(PyObject *self ATTRIBUTE_UNUSED, if (VIR_ALLOC_N(cpumap, cpumaplen) < 0) return PyErr_NoMemory(); - for (i = 0; i < tuple_size; i++) { + for (i = 0; i < MIN(cpunum, tuple_size); i++) { PyObject *flag = PyTuple_GetItem(pycpumap, i); bool b; -- 2.5.5

On Tue, Oct 25, 2016 at 12:42:23PM +0300, Konstantin Neumoin wrote:
If we pass large(more than cpunum) cpu mask to any libvirt_virDomainPin* methods, it could leads to crash. So we have to check tuple size and ignore extra tuple members.
Signed-off-by: Konstantin Neumoin <kneumoin@virtuozzo.com> --- libvirt-override.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/libvirt-override.c b/libvirt-override.c index fa3e2ca..83b760b 100644 --- a/libvirt-override.c +++ b/libvirt-override.c @@ -1327,7 +1327,7 @@ libvirt_virDomainPinVcpu(PyObject *self ATTRIBUTE_UNUSED, if (VIR_ALLOC_N(cpumap, cpumaplen) < 0) return PyErr_NoMemory();
- for (i = 0; i < tuple_size; i++) { + for (i = 0; i < MIN(cpunum, tuple_size); i++) {
I don't like it being called every single iteration of the loop. Temporary variable outside the loop would be nicer. Also since all these functions do the same thing, why not make a function for this and call it from all the places? It would also make a nice clean-up. Martin
participants (2)
-
Konstantin Neumoin
-
Martin Kletzander