Bug 1184131 - nodedev 'system' info can contain non-ascii text and control codes
Summary: nodedev 'system' info can contain non-ascii text and control codes
Keywords:
Status: CLOSED CURRENTRELEASE
Alias: None
Product: Fedora
Classification: Fedora
Component: libvirt
Version: 21
Hardware: x86_64
OS: Linux
unspecified
high
Target Milestone: ---
Assignee: Ján Tomko
QA Contact: Fedora Extras Quality Assurance
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2015-01-20 15:47 UTC by Hansen Tanjung
Modified: 2015-06-05 23:02 UTC (History)
14 users (show)

Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Clone Of:
Environment:
Last Closed: 2015-06-05 23:02:02 UTC
Type: Bug
Embargoed:


Attachments (Terms of Use)
Filter ascii and non ascii characters from the information given by the hardware vendors (1.04 KB, patch)
2015-03-17 10:14 UTC, francisco.marchena
no flags Details | Diff
SPEC file for RPMBUILD (37.73 KB, text/plain)
2015-03-18 17:20 UTC, vitalwonhyo
no flags Details
Patch for RPMBUILD (666 bytes, patch)
2015-03-18 17:21 UTC, vitalwonhyo
no flags Details | Diff


Links
System ID Private Priority Status Summary Last Updated
Red Hat Bugzilla 1217687 0 unspecified CLOSED dmidecode can contain non-UTF-8, libvirt generates invalid nodedev XML 2021-02-22 00:41:40 UTC

Internal Links: 1217687

Description Hansen Tanjung 2015-01-20 15:47:30 UTC
Description of problem:
I have a weird laptop motherboard that produce non ASCII information when quried. That character raise parsing error from xmlParseDoc().

This is relevant info when virt-manager running with debug parameter:
---
<device>
  <name>computer</name>
  <capability type='system'>
    <product>��������U310����</product>
    <hardware>
      <vendor>LENOVO</vendor>
      <version>�������U310���������������������</version>
      <serial>��������������������������������</serial>
      <uuid>771f691d-2d42-4f44-96d5-cac2dedad56b</uuid>
    </hardware>
    <firmware>
      <vendor>LENOVO</vendor>
      <version>65CN21WW</version>
      <release_date>12/26/2012</release_date>
    </firmware>
  </capability>
</device>

[Tue, 20 Jan 2015 21:41:35 virt-manager 29497] DEBUG (cli:208) Uncaught exception:
Traceback (most recent call last):
  File "/usr/share/virt-manager/virtManager/libvirtobject.py", line 230, in _reparse_xml
    self._xmlobj = self._build_xmlobj(self._get_raw_xml())
  File "/usr/share/virt-manager/virtManager/libvirtobject.py", line 233, in _build_xmlobj
    return self._parseclass(self.conn.get_backend(), parsexml=xml)
  File "/usr/share/virt-manager/virtManager/nodedev.py", line 27, in _parse_convert
    return NodeDevice.parse(conn, parsexml)
  File "/usr/share/virt-manager/virtinst/nodedev.py", line 92, in parse
    tmpdev = NodeDevice(conn, parsexml=xml, allow_node_instantiate=True)
  File "/usr/share/virt-manager/virtinst/nodedev.py", line 101, in __init__
    XMLBuilder.__init__(self, *args, **kwargs)
  File "/usr/share/virt-manager/virtinst/xmlbuilder.py", line 781, in __init__
    parent_xpath, relative_object_xpath)
  File "/usr/share/virt-manager/virtinst/xmlbuilder.py", line 683, in __init__
    self._parse(parsexml, parsexmlnode)
  File "/usr/share/virt-manager/virtinst/xmlbuilder.py", line 696, in _parse
    doc = libxml2.parseDoc(xml)
  File "/usr/lib64/python2.7/site-packages/libxml2.py", line 1325, in parseDoc
    if ret is None:raise parserError('xmlParseDoc() failed')
parserError: xmlParseDoc() failed
---

I can't change that motherboard info because BIOS also produce that. This error makes me can't make any new virtual component or machine, altough any virtual machine that produced before this error occur can run properly.

Version-Release number of selected component (if applicable):
libvirt.x86_64 1.2.9.1-2.fc21
virt-manager.noarch 1.1.0-4.git310f6527.fc21

How reproducible:
always

Steps to Reproduce:
1. Start virt-manager
2. Create a new virtual machine

Actual results:
Step-by-step creating new virtual machine stop at step 1 with error massage at dialog box "Error: xmlParseDoc() failed"

Expected results:
Success creating a new virtual machine

Additional info:
This parsing error seems related to bug 1072770 and bug 1074528 that had been closed, unfortunately my malformed device properties not the storage like the two previous bugs.

Comment 1 vitalwonhyo 2015-02-04 17:04:19 UTC
(In reply to Hansen Tanjung from comment #0)
> Description of problem:
> I have a weird laptop motherboard that produce non ASCII information when
> quried. That character raise parsing error from xmlParseDoc().
> 
> This is relevant info when virt-manager running with debug parameter:
> ---
> <device>
>   <name>computer</name>
>   <capability type='system'>
>     <product>��������U310����</product>
>     <hardware>
>       <vendor>LENOVO</vendor>
>       <version>�������U310���������������������</version>
>       <serial>��������������������������������</serial>
>       <uuid>771f691d-2d42-4f44-96d5-cac2dedad56b</uuid>
>     </hardware>
>     <firmware>
>       <vendor>LENOVO</vendor>
>       <version>65CN21WW</version>
>       <release_date>12/26/2012</release_date>
>     </firmware>
>   </capability>
> </device>
> 
> [Tue, 20 Jan 2015 21:41:35 virt-manager 29497] DEBUG (cli:208) Uncaught
> exception:
> Traceback (most recent call last):
>   File "/usr/share/virt-manager/virtManager/libvirtobject.py", line 230, in
> _reparse_xml
>     self._xmlobj = self._build_xmlobj(self._get_raw_xml())
>   File "/usr/share/virt-manager/virtManager/libvirtobject.py", line 233, in
> _build_xmlobj
>     return self._parseclass(self.conn.get_backend(), parsexml=xml)
>   File "/usr/share/virt-manager/virtManager/nodedev.py", line 27, in
> _parse_convert
>     return NodeDevice.parse(conn, parsexml)
>   File "/usr/share/virt-manager/virtinst/nodedev.py", line 92, in parse
>     tmpdev = NodeDevice(conn, parsexml=xml, allow_node_instantiate=True)
>   File "/usr/share/virt-manager/virtinst/nodedev.py", line 101, in __init__
>     XMLBuilder.__init__(self, *args, **kwargs)
>   File "/usr/share/virt-manager/virtinst/xmlbuilder.py", line 781, in
> __init__
>     parent_xpath, relative_object_xpath)
>   File "/usr/share/virt-manager/virtinst/xmlbuilder.py", line 683, in
> __init__
>     self._parse(parsexml, parsexmlnode)
>   File "/usr/share/virt-manager/virtinst/xmlbuilder.py", line 696, in _parse
>     doc = libxml2.parseDoc(xml)
>   File "/usr/lib64/python2.7/site-packages/libxml2.py", line 1325, in
> parseDoc
>     if ret is None:raise parserError('xmlParseDoc() failed')
> parserError: xmlParseDoc() failed
> ---
> 
> I can't change that motherboard info because BIOS also produce that. This
> error makes me can't make any new virtual component or machine, altough any
> virtual machine that produced before this error occur can run properly.
> 
> Version-Release number of selected component (if applicable):
> libvirt.x86_64 1.2.9.1-2.fc21
> virt-manager.noarch 1.1.0-4.git310f6527.fc21
> 
> How reproducible:
> always
> 
> Steps to Reproduce:
> 1. Start virt-manager
> 2. Create a new virtual machine
> 
> Actual results:
> Step-by-step creating new virtual machine stop at step 1 with error massage
> at dialog box "Error: xmlParseDoc() failed"
> 
> Expected results:
> Success creating a new virtual machine
> 
> Additional info:
> This parsing error seems related to bug 1072770 and bug 1074528 that had
> been closed, unfortunately my malformed device properties not the storage
> like the two previous bugs.

SAME Error With Me

[Wed, 04 Feb 2015 23:52:59 virt-manager 20222] DEBUG (connection:797) Using domain events
[Wed, 04 Feb 2015 23:52:59 virt-manager 20222] DEBUG (connection:831) Using network events
[Wed, 04 Feb 2015 23:52:59 virt-manager 20222] DEBUG (xmlbuilder:698) Error parsing xml=
<device>
  <name>computer</name>
  <capability type='system'>
    <product>��������U410����</product>
    <hardware>
      <vendor>LENOVO</vendor>
      <version>�������U410���������������������</version>
      <serial>��������������������������������</serial>
      <uuid>610b271e-f473-4454-ad81-afe332bff712</uuid>
    </hardware>
    <firmware>
      <vendor>LENOVO</vendor>
      <version>65CN21WW</version>
      <release_date>12/26/2012</release_date>
    </firmware>
  </capability>
</device>

Exception in thread nodedev=computer AddMediadev:
Traceback (most recent call last):
  File "/usr/lib64/python2.7/threading.py", line 813, in __bootstrap_inner
    self.run()
  File "/usr/lib64/python2.7/threading.py", line 766, in run
    self.__target(*self.__args, **self.__kwargs)
  File "/usr/share/virt-manager/virtManager/connection.py", line 847, in _add_thread
    mediadev = vmmMediaDevice.mediadev_from_nodedev(vobj)
  File "/usr/share/virt-manager/virtManager/mediadev.py", line 41, in mediadev_from_nodedev
    nodedev = dev.get_xmlobj()
  File "/usr/share/virt-manager/virtManager/libvirtobject.py", line 164, in get_xmlobj
    self._reparse_xml()
  File "/usr/share/virt-manager/virtManager/libvirtobject.py", line 230, in _reparse_xml
    self._xmlobj = self._build_xmlobj(self._get_raw_xml())
  File "/usr/share/virt-manager/virtManager/libvirtobject.py", line 233, in _build_xmlobj
    return self._parseclass(self.conn.get_backend(), parsexml=xml)
  File "/usr/share/virt-manager/virtManager/nodedev.py", line 27, in _parse_convert
    return NodeDevice.parse(conn, parsexml)
  File "/usr/share/virt-manager/virtinst/nodedev.py", line 92, in parse
    tmpdev = NodeDevice(conn, parsexml=xml, allow_node_instantiate=True)
  File "/usr/share/virt-manager/virtinst/nodedev.py", line 101, in __init__
    XMLBuilder.__init__(self, *args, **kwargs)
  File "/usr/share/virt-manager/virtinst/xmlbuilder.py", line 781, in __init__
    parent_xpath, relative_object_xpath)
  File "/usr/share/virt-manager/virtinst/xmlbuilder.py", line 683, in __init__
    self._parse(parsexml, parsexmlnode)
  File "/usr/share/virt-manager/virtinst/xmlbuilder.py", line 696, in _parse
    doc = libxml2.parseDoc(xml)
  File "/usr/lib64/python2.7/site-packages/libxml2.py", line 1325, in parseDoc
    if ret is None:raise parserError('xmlParseDoc() failed')
parserError: xmlParseDoc() failed


Bug I found Easy Way To Fix This Bug

download virt-manager:
git clone git://git.fedorahosted.org/virt-manager.git
cd virt-manager

edit file:
virtinst/xmlbuilder.py

change
doc = libxml2.parseDoc(xml)
to
xml = xml.decode("ascii", 'ignore')
doc = libxml2.parseDoc(xml)

./virt-manager 

It Work

Comment 2 francisco.marchena 2015-03-17 10:14:09 UTC
Created attachment 1002747 [details]
Filter ascii and non ascii characters from the information given by the hardware vendors

I've added also the ascii filter as vitalwonhyo suggested.

Comment 3 francisco.marchena 2015-03-17 10:15:52 UTC
Hello,

I have a different problem but it is related to this.

Use case:

- Using virt-manager-1.1.0-4.git310f6527.fc21.noarch or virt-manager master
- run: virt-manager --debug
- Error log:

[Tue, 17 Mar 2015 09:57:17 virt-manager 18951] DEBUG (connection:768) Using domain events
[Tue, 17 Mar 2015 09:57:17 virt-manager 18951] DEBUG (connection:802) Using network events
[Tue, 17 Mar 2015 09:57:17 virt-manager 18951] DEBUG (xmlbuilder:667) Error parsing xml=
<device>
  <name>computer</name>
  <capability type='system'>
    <product>7200-2004A</product>
    <hardware>
      <vendor>ZOOSTORM</vendor>
      <version>7200-2004A</version>
      <serial>CM015262-0</serial>
      <uuid>9402de03-8004-fb05-ec06-ed0700080009</uuid>
    </hardware>
    <firmware>
      <vendor>American Megatrends Inc.</vendor>
      <version>F4 UM1</version>
      <release_date>08/20/2014</release_date>
    </firmware>
  </capability>
</device>

Exception in thread nodedev=computer AddMediadev:
Traceback (most recent call last):
  File "/usr/lib64/python2.7/threading.py", line 813, in __bootstrap_inner
    self.run()
  File "/usr/lib64/python2.7/threading.py", line 766, in run
    self.__target(*self.__args, **self.__kwargs)
  File "/home/franred/virt-manager/virtManager/connection.py", line 818, in _add_thread
    mediadev = vmmMediaDevice.mediadev_from_nodedev(vobj)
  File "/home/franred/virt-manager/virtManager/mediadev.py", line 41, in mediadev_from_nodedev
    nodedev = dev.get_xmlobj()
  File "/home/franred/virt-manager/virtManager/libvirtobject.py", line 164, in get_xmlobj
    self._reparse_xml()
  File "/home/franred/virt-manager/virtManager/libvirtobject.py", line 230, in _reparse_xml
    self._xmlobj = self._build_xmlobj(self._get_raw_xml())
  File "/home/franred/virt-manager/virtManager/libvirtobject.py", line 233, in _build_xmlobj
    return self._parseclass(self.conn.get_backend(), parsexml=xml)
  File "/home/franred/virt-manager/virtManager/nodedev.py", line 27, in _parse_convert
    return NodeDevice.parse(conn, parsexml)
  File "/home/franred/virt-manager/virtinst/nodedev.py", line 92, in parse
    tmpdev = NodeDevice(conn, parsexml=xml, allow_node_instantiate=True)
  File "/home/franred/virt-manager/virtinst/nodedev.py", line 101, in __init__
    XMLBuilder.__init__(self, *args, **kwargs)
  File "/home/franred/virt-manager/virtinst/xmlbuilder.py", line 750, in __init__
    parent_xpath, relative_object_xpath)
  File "/home/franred/virt-manager/virtinst/xmlbuilder.py", line 652, in __init__
    self._parse(parsexml, parsexmlnode)
  File "/home/franred/virt-manager/virtinst/xmlbuilder.py", line 665, in _parse
    doc = libxml2.parseDoc(xml)
  File "/usr/lib64/python2.7/site-packages/libxml2.py", line 1325, in parseDoc
    if ret is None:raise parserError('xmlParseDoc() failed')
parserError: xmlParseDoc() failed

The error is because in  <serial>CM015262-0</serial> there is a non printable character so the xml parser failed to parse it.

The attached patch fixes this error for me.

Comment 4 vitalwonhyo 2015-03-18 17:20:41 UTC
Created attachment 1003344 [details]
SPEC file for RPMBUILD

Comment 5 vitalwonhyo 2015-03-18 17:21:30 UTC
Created attachment 1003345 [details]
Patch for RPMBUILD

Comment 6 vitalwonhyo 2015-03-18 17:23:06 UTC
(In reply to francisco.marchena from comment #2)
> Created attachment 1002747 [details]
> Filter ascii and non ascii characters from the information given by the
> hardware vendors
> 
> I've added also the ascii filter as vitalwonhyo suggested.

thank i has add spec and .patch use for rpmbuild new .rpm package with the fix..

Comment 7 Cole Robinson 2015-03-26 21:58:43 UTC
I'll add a workaround to virt-manager for the nodedev 'system' case, but the root issue here is that libvirt shouldn't be generating this bogus XML. So reassigning.

Comment 8 Cole Robinson 2015-03-26 22:09:30 UTC
Here's the virt-manager workaround:

commit e125aa69d8024fddb72dde9371f172061f388160
Author: Cole Robinson <crobinso>
Date:   Thu Mar 26 18:04:23 2015 -0400

    nodedev: Handle busted 'system' XML

francisco and vitalwonhyo, I adjusted your code to only work for node devices where you guys are seeing this problem, rather than do it for every XML parsing which would have a serious performance cost. And added test cases and docs. Thanks for the suggestions !

Comment 9 Ján Tomko 2015-03-30 11:07:24 UTC
I have sent a patch to strip control codes when generating XML:
https://www.redhat.com/archives/libvir-list/2015-March/msg01529.html

Hopefully that will generate XML that will pass validation:
virsh nodedev-dumpxml computer > computer.xml
virt-xml-validate computer.xml nodedev

Comment 11 Ján Tomko 2015-04-15 17:46:01 UTC
Fixed upstream by:
commit aeb5262e4397528d582682471cb8075141189465
    Strip control codes in virBufferEscapeString
commit 557107500b22d4a5ba7d1b09f5f516512dfca67b
    Strip control characters from sysfs attributes 
git describe: v1.2.14-194-gaeb5262 

Backported to v1.2.9-maint as of v1.2.9.2-10-g7eb973e

Comment 12 Fedora Update System 2015-04-28 16:54:50 UTC
libvirt-1.2.9.3-1.fc21 has been submitted as an update for Fedora 21.
https://admin.fedoraproject.org/updates/libvirt-1.2.9.3-1.fc21

Comment 13 Fedora Update System 2015-04-29 13:05:56 UTC
Package libvirt-1.2.9.3-1.fc21:
* should fix your issue,
* was pushed to the Fedora 21 testing repository,
* should be available at your local mirror within two days.
Update it with:
# su -c 'yum update --enablerepo=updates-testing libvirt-1.2.9.3-1.fc21'
as soon as you are able to.
Please go to the following url:
https://admin.fedoraproject.org/updates/FEDORA-2015-7150/libvirt-1.2.9.3-1.fc21
then log in and leave karma (feedback).

Comment 14 Hansen Tanjung 2015-04-30 04:01:45 UTC
Still not working for me.

Installed Packages
libvirt.x86_64               1.2.9.3-1.fc21                     @updates-testing
libxml2.x86_64               2.9.1-7.fc21                       @updates        
virt-manager.noarch          1.1.0-8.git310f6527.fc21           @updates        

Need another packages update?

Comment 15 Cole Robinson 2015-04-30 13:02:12 UTC
Hansen, did you restart libvirtd ?

Is virt-manager failing in the exact same way as reported in comment #0?

Comment 16 Hansen Tanjung 2015-04-30 19:00:48 UTC
Yes, i try to restart libvirtd and even to restart computer and still get the same error

Comment 17 Cole Robinson 2015-04-30 19:14:14 UTC
Thanks Hansen. Sorry but can you file a different bug then, this one is going to get autoclosed.

Please report:

sudo virsh nodedev-dumpxml computer > nodedev    and then upload output to the bug report (don't paste it)
sudo dmidecode > dmi   and then upload the output

Sorry for the inconvenience


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