Blob Blame Raw
From 803928d78f90b4a045a4682ee0c692bbf9f5c89d Mon Sep 17 00:00:00 2001
Message-Id: <803928d78f90b4a045a4682ee0c692bbf9f5c89d@dist-git>
From: Luyao Huang <lhuang@redhat.com>
Date: Wed, 22 Oct 2014 09:55:14 +0200
Subject: [PATCH] Fix parsing of 'flags' argument for bulk stats functions

https://bugzilla.redhat.com/show_bug.cgi?id=1155016

When 'flags' is set to
'libvirt.VIR_CONNECT_GET_ALL_DOMAINS_STATS_ENFORCE_STATS,
python will report a  error:

OverflowError: signed integer is greater than maximum

as VIR_CONNECT_GET_ALL_DOMAINS_STATS_ENFORCE_STATS is defined as 1<<31.
This happens as PyArg_ParseTuple's formatting string containing 'i' as a
modifier expects a signed integer.

With python >= 2.3, 'I' means unsigned int and 'i' means int so we
should use 'I' in the formatting string.

See: https://docs.python.org/2/c-api/arg.html

Signed-off-by: Luyao Huang <lhuang@redhat.com>
Signed-off-by: Peter Krempa <pkrempa@redhat.com>
(cherry picked from commit b3aa7da4bbc5f44f34cde8a9b719c5c2ecbf7f8b)
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
---
 libvirt-override.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/libvirt-override.c b/libvirt-override.c
index 872e33b..e072602 100644
--- a/libvirt-override.c
+++ b/libvirt-override.c
@@ -8024,7 +8024,7 @@ libvirt_virConnectGetAllDomainStats(PyObject *self ATTRIBUTE_UNUSED,
     unsigned int flags;
     unsigned int stats;
 
-    if (!PyArg_ParseTuple(args, (char *)"Oii:virConnectGetAllDomainStats",
+    if (!PyArg_ParseTuple(args, (char *)"OII:virConnectGetAllDomainStats",
                           &pyobj_conn, &stats, &flags))
         return NULL;
     conn = (virConnectPtr) PyvirConnect_Get(pyobj_conn);
@@ -8060,7 +8060,7 @@ libvirt_virDomainListGetStats(PyObject *self ATTRIBUTE_UNUSED,
     unsigned int flags;
     unsigned int stats;
 
-    if (!PyArg_ParseTuple(args, (char *)"OOii:virDomainListGetStats",
+    if (!PyArg_ParseTuple(args, (char *)"OOII:virDomainListGetStats",
                           &pyobj_conn, &py_domlist, &stats, &flags))
         return NULL;
 
-- 
2.1.3