Bug 1002558 - A PyList usage mistake in Function libvirt_lxc_virDomainLxcOpenNamespace.
A PyList usage mistake in Function libvirt_lxc_virDomainLxcOpenNamespace.
Status: CLOSED CURRENTRELEASE
Product: Red Hat Enterprise Linux 7
Classification: Red Hat
Component: libvirt (Show other bugs)
7.0
Unspecified Unspecified
unspecified Severity unspecified
: rc
: ---
Assigned To: Eric Blake
Virtualization Bugs
:
: 1003829 (view as bug list)
Depends On: 1002383
Blocks:
  Show dependency treegraph
 
Reported: 2013-08-29 08:55 EDT by Eric Blake
Modified: 2014-06-17 20:54 EDT (History)
7 users (show)

See Also:
Fixed In Version: libvirt-1.1.1-4.el7
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: 1002383
Environment:
Last Closed: 2014-06-13 07:08:44 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 Eric Blake 2013-08-29 08:55:21 EDT
cloning to rhel

+++ This bug was initially created as a clone of Bug #1002383 +++

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:

--- Additional comment from Eric Blake on 2013-08-29 06:54:43 MDT ---

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>
Comment 2 Alex Jia 2013-09-03 06:20:32 EDT
I also met this issue today.

# cat /tmp/test.py
import sys
import libvirt_lxc

if __name__ == "__main__":
    name = sys.argv[1]
    con = libvirt_lxc.libvirt.open('lxc:///')
    dom = con.lookupByName(name)
    fd = libvirt_lxc.lxcOpenNamespace(dom, 0)
    print 'The fd length=%s\nfd=%s' % (len(fd), fd)

# python /tmp/test.py sandbox
The fd length=10
fd=[<NULL>, <NULL>, <NULL>, <NULL>, <NULL>, 12, 13, 14, 15, 16]
Comment 4 Luwen Su 2013-09-10 02:28:31 EDT
libvirt-1.1.1-4.el7

Same steps with Comment 2:
# python test.py test
The fd length=6
fd=[13, 14, 15, 16, 17, 18]

The fd's length equals to the length of fd , so set VERIFIED
Comment 5 Daniel Berrange 2013-09-20 08:05:51 EDT
*** Bug 1003829 has been marked as a duplicate of this bug. ***
Comment 6 Ludek Smid 2014-06-13 07:08:44 EDT
This request was resolved in Red Hat Enterprise Linux 7.0.

Contact your manager or support representative in case you have further questions about the request.

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