Bug 1002383 - A PyList usage mistake in Function libvirt_lxc_virDomainLxcOpenNamespace.
A PyList usage mistake in Function libvirt_lxc_virDomainLxcOpenNamespace.
Status: CLOSED NEXTRELEASE
Product: Virtualization Tools
Classification: Community
Component: libvirt (Show other bugs)
unspecified
Unspecified Unspecified
unspecified Severity unspecified
: ---
: ---
Assigned To: Libvirt Maintainers
:
Depends On:
Blocks: 1002558
  Show dependency treegraph
 
Reported: 2013-08-29 01:12 EDT by QiangGuan
Modified: 2013-08-29 08:55 EDT (History)
2 users (show)

See Also:
Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
: 1002558 (view as bug list)
Environment:
Last Closed: 2013-08-29 08:54:43 EDT
Type: Bug
Regression: ---
Mount Type: ---
Documentation: ---
CRM:
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---


Attachments (Terms of Use)

  None (edit)
Description QiangGuan 2013-08-29 01:12:28 EDT
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 08:54:43 EDT
Will be fixed in 1.1.2:

commit c26181495f3c98870d0794052246718f5d3d8dd6
Author: Guan Qiang <hzguanqiang@corp.netease.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@redhat.com>

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