Bug 2019701

Summary: libvirt crash when "virsh nodedev-define" with wrong formatted <uuid> in xml
Product: Red Hat Enterprise Linux 9 Reporter: zhentang <zhetang>
Component: libvirtAssignee: Virtualization Maintenance <virt-maint>
Status: CLOSED DUPLICATE QA Contact: Virtualization Bugs <virt-bugs>
Severity: unspecified Docs Contact:
Priority: unspecified    
Version: 9.0CC: pkrempa, virt-maint
Target Milestone: rc   
Target Release: ---   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2021-11-03 08:12:05 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:

Description zhentang 2021-11-03 07:52:07 UTC
Description of problem:
libvirt crash when "virsh nodedev-define" with wrong formatted <uuid> in xml 

Version-Release number of selected component (if applicable):
libvirt-7.8.0-1.el9
qemu-kvm-6.1.0-6.el9

How reproducible:
100%

Steps to Reproduce:
1.prepare a xml file for define mdev device with an invalid uuid
#vi mdev.xml
<device>
  <name>mdev_4187c971_5830_4a17_aed7_b1410c7eb63a_0000_5b_00_0</name>
  <parent>computer</parent>
  <capability type='mdev'>
    <type id='nvidia-262'/>
    <uuid>4187aed7-b1410c7eb63a</uuid>
    <iommuGroup number='0'/>
  </capability>
</device>



2.try to define the device
# virsh nodedev-define md.xml 
error: Disconnected from qemu:///system due to end of file
error: Failed to define node device from 'md.xml'
error: End of file while reading data: Input/output error

Error message in /var/log/libvirt/libvirtd.log 
"2021-11-03 07:42:13.601+0000: 18508: error : virNodeDevCapMdevParseXML:1924 : internal error: Invalid uuid '4187aed7-b1410c7eb63a' for new mdev device"


3.

Actual results:
device define failed and libvirt crash 

Expected results:
output error message like "error: internal error: malformed uuid element" when device define failed

Additional info:

Comment 1 Peter Krempa 2021-11-03 08:12:05 UTC
This is the same root cause as https://bugzilla.redhat.com/show_bug.cgi?id=2014139 . The parser returns a NULL object if the XML is invalid and then we tried to invoke the post-parse callbacks.

*** This bug has been marked as a duplicate of bug 2014139 ***