]> git.ipfire.org Git - thirdparty/libvirt.git/commit
util: fix handling of unspecified port in URI
authorDaniel P. Berrangé <berrange@redhat.com>
Tue, 13 Nov 2018 11:30:03 +0000 (11:30 +0000)
committerDaniel P. Berrangé <berrange@redhat.com>
Wed, 14 Nov 2018 17:09:41 +0000 (17:09 +0000)
commit87c972552c11597097c5c22f4684d23c3f29a571
tree7b8a5d677746772142b3a53955ecb66c6458fac4
parent66a85cb1360cdd9498cea055ff5a5c4d2bc46106
util: fix handling of unspecified port in URI

When no server name is provided in the URI, modern versions of libxml2
will set the port to '-1'. This is a change from behaviour with earlier
versions which set it to 0.

Libvirt expects the port to be 0 in these cases and as a result we get a
bug when connecting to URIs which lack a server name:

$ virsh  -c test+ssh:///default list
error: failed to connect to the hypervisor
error: Cannot recv data: Bad port '-1': Connection reset by peer

This libxml2 change was attempting to fix another bug identified by
libvirt where it didn't roundtrip URIs correctly in:

  https://github.com/GNOME/libxml2/commit/beb7281055dbf0ed4d041022a67c6c5cfd126f25

Essentially libxml2 was not expecting apps to look at the URI port
field when the server name is not provided. This was a reasonable
assumption, but none the less libvirt did look at it :-)

The fix is to ensure we explicitly set port to 0 when server name
is not present, avoiding undefined behaviour for the port field in
libxml2.

Reviewed-by: Erik Skultety <eskultet@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
src/util/viruri.c