Bug 36098 - "xm list" aborts with xml.parsers.expat.ExpatError
"xm list" aborts with xml.parsers.expat.ExpatError
Status: CLOSED FIXED
Product: UCS
Classification: Unclassified
Component: Virtualization - Xen
UCS 3.2
All Linux
: P5 normal (vote)
: UCS 3.2-4-errata
Assigned To: Philipp Hahn
Erik Damrose
:
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2014-10-08 16:33 CEST by Philipp Hahn
Modified: 2015-01-21 12:23 CET (History)
2 users (show)

See Also:
What kind of report is it?: ---
What type of bug is this?: ---
Who will be affected by this bug?: ---
How will those affected feel about the bug?: ---
User Pain:
Enterprise Customer affected?:
School Customer affected?:
ISV affected?:
Waiting Support:
Flags outvoted (downgraded) after PO Review:
Ticket number:
Bug group (optional):
Max CVSS v3 score:
hahn: Patch_Available+


Attachments
HACK system XML parser to ignore ASCII control characters (453 bytes, text/plain)
2014-10-08 16:33 CEST, Philipp Hahn
Details
xend: Fix hex decoding in sxp.Parser (2.96 KB, patch)
2014-10-15 21:00 CEST, Philipp Hahn
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Philipp Hahn univentionstaff 2014-10-08 16:33:03 CEST
Created attachment 6149 [details]
HACK system XML parser to ignore ASCII control characters

Ticket#2014100821000491

This happens when the desription contains umlauts, as "xm list" uses the XML-RPC-API to XenD while "virsh list" uses the older HTTP-SXPR-API.

Unexpected error: <class 'xml.parsers.expat.ExpatError'>

Please report to xen-devel@lists.xensource.com
Traceback (most recent call last):
  File "/usr/sbin/xm", line 7, in <module>
    main.main(sys.argv)
  File "/usr/lib/python2.6/dist-packages/xen/xm/main.py", line 3983, in main
    _, rc = _run_cmd(cmd, cmd_name, args)
  File "/usr/lib/python2.6/dist-packages/xen/xm/main.py", line 4007, in _run_cmd
    return True, cmd(args)
  File "/usr/lib/python2.6/dist-packages/xen/xm/main.py", line 1034, in xm_list
    doms = getDomains(params, state, use_long, pool)
  File "/usr/lib/python2.6/dist-packages/xen/xm/main.py", line 981, in getDomains
    return [server.xend.domain(dom, full) for dom in domain_names]
  File "/usr/lib/python2.6/xmlrpclib.py", line 1199, in __call__
    return self.__send(self.__name, args)
  File "/usr/lib/python2.6/dist-packages/xen/util/xmlrpcclient.py", line 124, in __request
    response = xmlrpclib.ServerProxy.__request(self, methodname, params)
  File "/usr/lib/python2.6/xmlrpclib.py", line 1489, in __request
    verbose=self.__verbose
  File "/usr/lib/python2.6/dist-packages/xen/util/xmlrpcclient.py", line 56, in request
    request_body, verbose)
  File "/usr/lib/python2.6/xmlrpclib.py", line 1253, in request
    return self._parse_response(h.getfile(), sock)
  File "/usr/lib/python2.6/xmlrpclib.py", line 1387, in _parse_response
    p.feed(response)
  File "/usr/lib/python2.6/xmlrpclib.py", line 601, in feed
    self._parser.Parse(data, 0)
xml.parsers.expat.ExpatError: not well-formed (invalid token): line 46, column 28


/var/lib/xend/domains/5cf28d78-0a2b-a455-96df-a1e634553ac6/config.sxp looks right, so it seems to be a bug in XenD generating invalid XML output.
Comment 1 Philipp Hahn univentionstaff 2014-10-10 11:15:20 CEST
This is a XenD bug, which is hidden by UVMMd: albeit the broken description is fetched through libvirt, it gets overwritten by the still correct variant from LDAP:

# virsh -c xen://lynx4.phahn.dev/ desc 783df368-2a6b-ae6d-88b5-ec8ffda059e4
Fr\\xc3\\xbcher war alles Schl\\xc3\\xa4cha!\\xe2\\x82\\xac

# udm uvmm/info list --filter uuid=783df368-2a6b-ae6d-88b5-ec8ffda059e4 | grep desc
  description: Früher war alles Schlächa!€

# grep Fr /var/lib/xend/domains/783df368-2a6b-ae6d-88b5-ec8ffda059e4/config.sxp 
        'Fr\\xc3\\xbcher war aller Schl\\xc3\\xa4cha!\\xe2\\x82\\xac'
        'Fr\\xc3\\xbcher war aller Schl\\xc3\\xa4cha!\\xe2\\x82\\xac'

For each round of "virsh edit $DOM" the escaping get duplicated.
Comment 2 Philipp Hahn univentionstaff 2014-10-14 10:11:25 CEST
src/xenconfig/xen_sxpr.c:
 XenD -> libvirt
1128     if (sexpr_node_copy(root, "domain/description", &def->description) < 0)       
1129         goto error;
 libvirt -> XenD
2222     if (def->description)
2223         virBufferEscapeSexpr(&buf, "(description '%s')", def->description);
Comment 3 Philipp Hahn univentionstaff 2014-10-15 21:00:38 CEST
Created attachment 6173 [details]
xend: Fix hex decoding in sxp.Parser

"xm list" sometimes failes with the following traceback:
> Traceback (most recent call last):
>   File "/root/36098_xend-expat.py", line 84, in <module>
>     main_xmlrpc()
>   File "/root/36098_xend-expat.py", line 50, in main_xmlrpc
>     result = xend.xend.domain(UUID)
>   File "/usr/lib/python2.6/xmlrpclib.py", line 1199, in __call__
>     return self.__send(self.__name, args)
>   File "/usr/lib/python2.6/xmlrpclib.py", line 1489, in __request
>     verbose=self.__verbose
>   File "/usr/lib/python2.6/xmlrpclib.py", line 1253, in request
>     return self._parse_response(h.getfile(), sock)
>   File "/usr/lib/python2.6/xmlrpclib.py", line 1387, in _parse_response
>     p.feed(response)
>   File "/usr/lib/python2.6/xmlrpclib.py", line 601, in feed
>     self._parser.Parse(data, 0)
> xml.parsers.expat.ExpatError: not well-formed (invalid token): line 45, column 18

This happens when the descriptive text for a VM contains
non-ASCII-characters, which xen.xend.sxp.show() converts to Python
hex-escapes:
> print repr(unichr(8364).encode('UTF-8'))
> '\xe2\x82\xac'

On read-back those are processed by xen.xend.sxp.Parser.state_hex(),
which is broken: 'a'..'f' respective 'A'..'F' are converted to 0..5
instead of 10..15. Thus the above sequence gets read back as:
'B\x82\x02'. When converted to XML this produces invalid XML, which
breaks expat.

Use Pythont int(..., 16) instead.
Comment 4 Philipp Hahn univentionstaff 2014-10-15 22:35:50 CEST
Sent upstream: <http://lists.xenproject.org/archives/html/xen-devel/2014-10/msg01819.html>
Comment 5 Philipp Hahn univentionstaff 2014-12-03 13:00:16 CET
r56410 | Bug #36098 xen: Fix hex decoding in sxp.Parser

Package: xen-4.1
Version: 4.1.3-17.43.201412031229
Branch: ucs_3.2-0
Scope: errata3.2-4

r56413 | Bug #36098 xen: Fix hex decoding in sxp.Parser YAML
 2014-12-03-xen-4.1.yaml
Comment 6 Erik Damrose univentionstaff 2015-01-21 12:20:25 CET
Whoops, forgot to actually set this bug to verified..
OK: code change
OK: having umlauts in the VM description does no longer crash xm list
OK: YAML
Verified
Comment 7 Moritz Muehlenhoff univentionstaff 2015-01-21 12:23:29 CET
http://errata.univention.de/ucs/3.2/274.html