Note: This bug is displayed in read-only format because the product is no longer active in Red Hat Bugzilla.
RHEL Engineering is moving the tracking of its product development work on RHEL 6 through RHEL 9 to Red Hat Jira (issues.redhat.com). If you're a Red Hat customer, please continue to file support cases via the Red Hat customer portal. If you're not, please head to the "RHEL project" in Red Hat Jira and file new tickets here. Individual Bugzilla bugs in the statuses "NEW", "ASSIGNED", and "POST" are being migrated throughout September 2023. Bugs of Red Hat partners with an assigned Engineering Partner Manager (EPM) are migrated in late September as per pre-agreed dates. Bugs against components "kernel", "kernel-rt", and "kpatch" are only migrated if still in "NEW" or "ASSIGNED". If you cannot log in to RH Jira, please consult article #7032570. That failing, please send an e-mail to the RH Jira admins at rh-issues@redhat.com to troubleshoot your issue as a user management inquiry. The email creates a ServiceNow ticket with Red Hat. Individual Bugzilla bugs that are migrated will be moved to status "CLOSED", resolution "MIGRATED", and set with "MigratedToJIRA" in "Keywords". The link to the successor Jira issue will be found under "Links", have a little "two-footprint" icon next to it, and direct you to the "RHEL project" in Red Hat Jira (issue links are of type "https://issues.redhat.com/browse/RHEL-XXXX", where "X" is a digit). This same link will be available in a blue banner at the top of the page informing you that that bug has been migrated.

Bug 1002558

Summary: A PyList usage mistake in Function libvirt_lxc_virDomainLxcOpenNamespace.
Product: Red Hat Enterprise Linux 7 Reporter: Eric Blake <eblake>
Component: libvirtAssignee: Eric Blake <eblake>
Status: CLOSED CURRENTRELEASE QA Contact: Virtualization Bugs <virt-bugs>
Severity: unspecified Docs Contact:
Priority: unspecified    
Version: 7.0CC: acathrow, ajia, cwei, dyuan, eblake, hzguanqiang, lsu
Target Milestone: rc   
Target Release: ---   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
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 11:08:44 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:
Bug Depends On: 1002383    
Bug Blocks:    

Description Eric Blake 2013-08-29 12:55:21 UTC
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.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>

Comment 2 Alex Jia 2013-09-03 10:20:32 UTC
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 06:28:31 UTC
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 Berrangé 2013-09-20 12:05:51 UTC
*** Bug 1003829 has been marked as a duplicate of this bug. ***

Comment 6 Ludek Smid 2014-06-13 11:08:44 UTC
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.