Bug 1002383 - A PyList usage mistake in Function libvirt_lxc_virDomainLxcOpenNamespace.
Summary: A PyList usage mistake in Function libvirt_lxc_virDomainLxcOpenNamespace.
Keywords:
Status: CLOSED NEXTRELEASE
Alias: None
Product: Virtualization Tools
Classification: Community
Component: libvirt
Version: unspecified
Hardware: Unspecified
OS: Unspecified
unspecified
unspecified
Target Milestone: ---
Assignee: Libvirt Maintainers
QA Contact:
URL:
Whiteboard:
Depends On:
Blocks: 1002558
TreeView+ depends on / blocked
 
Reported: 2013-08-29 05:12 UTC by QiangGuan
Modified: 2013-08-29 12:55 UTC (History)
2 users (show)

Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Clone Of:
: 1002558 (view as bug list)
Environment:
Last Closed: 2013-08-29 12:54:43 UTC
Embargoed:


Attachments (Terms of Use)

Description QiangGuan 2013-08-29 05:12:28 UTC
Description of problem:
In function libvirt_lxc_virDomainLxcOpenNamespace, the fdlist gotten by virDomainLxcOpenNamespace was converted to a Python List, which is initiated by PyList_New with a size of fdlist. Then each fd from fdlist is append to the Python List, which will make the python list size double of the fdlist length.

Version-Release number of selected component (if applicable):
1.0.2

How reproducible:
make a gdb debug

Steps to Reproduce:
1. write a python program to call libvirt_lxc.lxcOpenNamespace and set a pdb breakpoint.
2. gdb attach to the python process.
3. Then through gdb you will see the whole process Just as Actual results show.

Actual results:
gdb) l libvirt-lxc-override.c:58,85
58      static PyObject *
59      libvirt_lxc_virDomainLxcOpenNamespace(PyObject *self ATTRIBUTE_UNUSED,
60                                            PyObject *args) {
61          PyObject *py_retval;
62          virDomainPtr domain;
63          PyObject *pyobj_domain;
64          unsigned int flags;
65          int c_retval;
66          int *fdlist = NULL;
67          size_t i;
68
69          if (!PyArg_ParseTuple(args, (char *)"Oi:virDomainLxcOpenNamespace",
70                                &pyobj_domain, &flags))
71              return NULL;
72          domain = (virDomainPtr) PyvirDomain_Get(pyobj_domain);
73
74          if (domain == NULL)
75              return VIR_PY_NONE;
76          LIBVIRT_BEGIN_ALLOW_THREADS;
77          c_retval = virDomainLxcOpenNamespace(domain, &fdlist, flags);
78          LIBVIRT_END_ALLOW_THREADS;
79
80          if (c_retval < 0)
81              return VIR_PY_NONE;
82
83          py_retval = PyList_New(c_retval);
84          for (i = 0; i < c_retval; i++) {
85              PyObject *item = NULL;
(gdb) l libvirt-lxc-override.c:58,99
58      static PyObject *
59      libvirt_lxc_virDomainLxcOpenNamespace(PyObject *self ATTRIBUTE_UNUSED,
60                                            PyObject *args) {
61          PyObject *py_retval;
62          virDomainPtr domain;
63          PyObject *pyobj_domain;
64          unsigned int flags;
65          int c_retval;
66          int *fdlist = NULL;
67          size_t i;
68
69          if (!PyArg_ParseTuple(args, (char *)"Oi:virDomainLxcOpenNamespace",
70                                &pyobj_domain, &flags))
71              return NULL;
72          domain = (virDomainPtr) PyvirDomain_Get(pyobj_domain);
73
74          if (domain == NULL)
75              return VIR_PY_NONE;
76          LIBVIRT_BEGIN_ALLOW_THREADS;
77          c_retval = virDomainLxcOpenNamespace(domain, &fdlist, flags);
78          LIBVIRT_END_ALLOW_THREADS;
79
80          if (c_retval < 0)
81              return VIR_PY_NONE;
82
83          py_retval = PyList_New(c_retval);
84          for (i = 0; i < c_retval; i++) {
85              PyObject *item = NULL;
86
87              if ((item = PyInt_FromLong(fdlist[i])) == NULL)
88                  goto error;
89
90              if (PyList_Append(py_retval, item) < 0) {
91                  Py_DECREF(item);
92                  goto error;
93              }
94          }
95          return py_retval;
96
97      error:
98          for (i = 0; i < c_retval; i++) {
99              VIR_FORCE_CLOSE(fdlist[i]);
(gdb) b libvirt-lxc-override.c:83
Breakpoint 1 at 0x7ff6c8bc4db2: file libvirt-lxc-override.c, line 83.
(gdb) b libvirt-lxc-override.c:95
Breakpoint 2 at 0x7ff6c8bc4e5b: file libvirt-lxc-override.c, line 95.
(gdb) c
Continuing.

Breakpoint 1, libvirt_lxc_virDomainLxcOpenNamespace (self=0x0, args=0x2ead3b0) at libvirt-lxc-override.c:83
83          py_retval = PyList_New(c_retval);
(gdb) n
84          for (i = 0; i < c_retval; i++) {
(gdb) p PyList_Size(py_retval)
$1 = 5
(gdb) c
Continuing.

Breakpoint 2, libvirt_lxc_virDomainLxcOpenNamespace (self=0x0, args=0x2ead3b0) at libvirt-lxc-override.c:95
95          return py_retval;
(gdb) p PyList_Size(py_retval)
$2 = 10
(gdb) 

Expected results:
Above at the end, the PyList_Size(py_retval) should be 5.

Additional info:

Comment 1 Eric Blake 2013-08-29 12:54:43 UTC
Will be fixed in 1.1.2:

commit c26181495f3c98870d0794052246718f5d3d8dd6
Author: Guan Qiang <hzguanqiang.com>
Date:   Thu Aug 29 19:02:25 2013 +0800

    python: Fix a PyList usage mistake
    
    Fix PyList usage mistake in Function libvirt_lxc_virDomainLxcOpenNamespace.
    
    https://bugzilla.redhat.com/show_bug.cgi?id=1002383
    
    Signed-off-by: Eric Blake <eblake>


Note You need to log in before you can comment on or make changes to this bug.