From: Peter Krempa Date: Tue, 7 Nov 2017 15:20:23 +0000 (+0100) Subject: util: storage: Fix parsing of IPv6 portal address for iSCSI X-Git-Url: http://xenbits.xensource.com/gitweb?a=commitdiff_plain;h=0a3bae7d2270b86a7042b1970360851bf7ebbdb3;p=libvirt.git util: storage: Fix parsing of IPv6 portal address for iSCSI Split on the last colon and avoid parsing port if the split remainder contains the closing square bracket, so that IPv6 addresses are interpreted correctly. --- diff --git a/src/util/virstoragefile.c b/src/util/virstoragefile.c index 9cee643121..45a6dea8a0 100644 --- a/src/util/virstoragefile.c +++ b/src/util/virstoragefile.c @@ -3016,7 +3016,8 @@ virStorageSourceParseBackingJSONiSCSI(virStorageSourcePtr src, if (VIR_STRDUP(src->hosts->name, portal) < 0) goto cleanup; - if ((port = strchr(src->hosts->name, ':'))) { + if ((port = strrchr(src->hosts->name, ':')) && + !strchr(port, ']')) { if (virStringParsePort(port + 1, &src->hosts->port) < 0) goto cleanup; diff --git a/tests/virstoragetest.c b/tests/virstoragetest.c index 8a5ff078cf..806c5465ce 100644 --- a/tests/virstoragetest.c +++ b/tests/virstoragetest.c @@ -1578,6 +1578,26 @@ mymain(void) "\n" " \n" "\n"); + TEST_BACKING_PARSE("json:{\"file\":{\"driver\":\"iscsi\"," + "\"transport\":\"tcp\"," + "\"portal\":\"[2001::0]:1234\"," + "\"target\":\"iqn.2016-12.com.virttest:emulated-iscsi-noauth.target\"," + "\"lun\":6" + "}" + "}", + "\n" + " \n" + "\n"); + TEST_BACKING_PARSE("json:{\"file\":{\"driver\":\"iscsi\"," + "\"transport\":\"tcp\"," + "\"portal\":\"[2001::0]\"," + "\"target\":\"iqn.2016-12.com.virttest:emulated-iscsi-noauth.target\"," + "\"lun\":6" + "}" + "}", + "\n" + " \n" + "\n"); TEST_BACKING_PARSE("json:{\"file\":{\"driver\":\"sheepdog\"," "\"vdi\":\"test\"," "\"server\":{ \"type\":\"inet\","