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 1320893 - libvirt-python: rename a domain with empty string will make it disappear
Summary: libvirt-python: rename a domain with empty string will make it disappear
Keywords:
Status: CLOSED ERRATA
Alias: None
Product: Red Hat Enterprise Linux 7
Classification: Red Hat
Component: libvirt
Version: 7.3
Hardware: x86_64
OS: Linux
unspecified
medium
Target Milestone: rc
: ---
Assignee: Martin Kletzander
QA Contact: Virtualization Bugs
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2016-03-24 09:39 UTC by Kairui Song
Modified: 2016-11-03 18:40 UTC (History)
6 users (show)

Fixed In Version: libvirt-2.0.0-1.el7
Doc Type: Bug Fix
Doc Text:
Clone Of:
Environment:
Last Closed: 2016-11-03 18:40:44 UTC
Target Upstream Version:
Embargoed:


Attachments (Terms of Use)


Links
System ID Private Priority Status Summary Last Updated
Red Hat Product Errata RHSA-2016:2577 0 normal SHIPPED_LIVE Moderate: libvirt security, bug fix, and enhancement update 2016-11-03 12:07:06 UTC

Description Kairui Song 2016-03-24 09:39:34 UTC
Description of problem:
libvirt-python: rename a domain with empty string won't raise exception, and restart libvirtd that domain will disappear.


Version-Release number of selected component (if applicable):
libvirt-1.3.2-1.el7.x86_64
libvirt-python-1.3.2-1.el7.x86_64


How reproducible:
100%


Steps to Reproduce:
1.Create a guest vm and shut it down.

look like this:

# virsh list --all
 Id    Name                           State
----------------------------------------------------
 -     libvirt_test_api               shut off


2.run follow script in python

>>> import libvirt
>>> conn = libvirt.open()
>>> dom = conn.lookupByName('libvirt_test_api')
>>> dom.rename('', 0)
0

3.Domain was renamed, name is empty in virsh

# virsh list --all        
 Id    Name                           State
----------------------------------------------------
 -                                    shut off

4.Restart libvirtd and domain disappeard

# systemctl restart libvirtd

# virsh list --all          
 Id    Name                           State
----------------------------------------------------


Actual results:
Domain was renamed to a empty name and disappeared after restart libvirtd


Expected results:
Exception raises when try to rename a domain with empty string.


Additional info:
1.virsh gives error on empty domain name:

# virsh domrename 'libvirt_test_api' ''
error: Failed to get option 'new-name': Option argument is empty

2.At libvirt/src/libvirt-domain.c:8759
virCheckNonNullArgGoto(new_name, error);

libvirt only check is 'new_name' is a NULL pointer, didn't check if the string it pointing is a empty string.
replace with virCheckNonEmptyStringArgGoto(new_name, error) should fix it, but I'm not sure if it is the hyper-visor's driver's job to check it, or libvirt-python should check it.

Comment 2 Peter Krempa 2016-03-24 09:48:17 UTC
Moving to libvirt as the bug is in the API itself.

(In reply to Kairui Song from comment #0)
>
> Additional info:
> 1.virsh gives error on empty domain name:
> 
> # virsh domrename 'libvirt_test_api' ''
> error: Failed to get option 'new-name': Option argument is empty

This is due to the implementation of virsh, the API allows it, which is accessible directly via the python binding.

Comment 4 Martin Kletzander 2016-06-22 15:48:33 UTC
Patch proposed upstream:

https://www.redhat.com/archives/libvir-list/2016-June/msg01536.html

Comment 5 Martin Kletzander 2016-06-24 09:16:08 UTC
Fixed upstream with v1.3.5-429-g428d2dfdb8ca:
commit 428d2dfdb8ca41fde215364a06b5bd43901b5817
Author: Martin Kletzander <mkletzan>
Date:   Wed Jun 22 17:27:46 2016 +0200

    Don't allow raneming domains to empty strings

Comment 7 zhe peng 2016-07-06 08:33:16 UTC
I can reproduce this issue.
verify with libvirt-2.0.0-1.el7.x86_64

step:
1. use python
 python
Python 2.7.5 (default, May  4 2016, 07:14:23) 
[GCC 4.8.5 20150623 (Red Hat 4.8.5-4)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import libvirt
>>> conn = libvirt.open()
>>> dom = conn.lookupByName('q35')
>>> dom.rename('', 0)
libvirt: Domain Config error : string new_name in virDomainRename must not be empty
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib64/python2.7/site-packages/libvirt.py", line 2126, in rename
    if ret == -1: raise libvirtError ('virDomainRename() failed', dom=self)
libvirt.libvirtError: string new_name in virDomainRename must not be empty
>>> 

2. use virsh
# virsh domrename q35 ''
error: Failed to get option 'new-name': Option argument is empty

# virsh domrename q35 ' '
Domain successfully renamed

# virsh list --all
 Id    Name                           State
----------------------------------------------------
 -                                    shut off

# systemctl restart libvirtd
# virsh list --all
 Id    Name                           State
----------------------------------------------------
 -                                    shut off


# virsh domrename ' ' q35
Domain successfully renamed

# virsh list --all
 Id    Name                           State
----------------------------------------------------
 -     q35                            shut off

worked as expect, move to verified.

Comment 9 errata-xmlrpc 2016-11-03 18:40:44 UTC
Since the problem described in this bug report should be
resolved in a recent advisory, it has been closed with a
resolution of ERRATA.

For information on the advisory, and where to find the updated
files, follow the link below.

If the solution does not work for you, open a new bug report.

https://rhn.redhat.com/errata/RHSA-2016-2577.html


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