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:


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.