]> xenbits.xensource.com Git - libvirt.git/commitdiff
virDomainDiskAddISCSIPoolSourceHost: Sanitize handling of string list
authorPeter Krempa <pkrempa@redhat.com>
Wed, 5 Feb 2020 11:24:28 +0000 (12:24 +0100)
committerPeter Krempa <pkrempa@redhat.com>
Mon, 10 Feb 2020 16:26:26 +0000 (17:26 +0100)
Use virStringSplitCount instead of virStringSplit so that we can drop
the call to virStringListLength and use VIR_AUTOSTRINGLIST to declare
it and allow removal of the cleanup section.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
src/conf/domain_conf.c

index 51ae520897a2400ad763a01f6e3be9be0a8dc07c..a1458c03453aa946711950201902dc3a5b2a20eb 100644 (file)
@@ -31329,7 +31329,8 @@ virDomainDiskAddISCSIPoolSourceHost(virDomainDiskDefPtr def,
                                     virStoragePoolDefPtr pooldef)
 {
     int ret = -1;
-    char **tokens = NULL;
+    VIR_AUTOSTRINGLIST tokens = NULL;
+    size_t ntokens;
 
     /* Only support one host */
     if (pooldef->source.nhost != 1) {
@@ -31350,10 +31351,10 @@ virDomainDiskAddISCSIPoolSourceHost(virDomainDiskDefPtr def,
         pooldef->source.hosts[0].port : 3260;
 
     /* iscsi volume has name like "unit:0:0:1" */
-    if (!(tokens = virStringSplit(def->src->srcpool->volume, ":", 0)))
+    if (!(tokens = virStringSplitCount(def->src->srcpool->volume, ":", 0, &ntokens)))
         goto cleanup;
 
-    if (virStringListLength((const char * const *)tokens) != 4) {
+    if (ntokens != 4) {
         virReportError(VIR_ERR_INTERNAL_ERROR,
                        _("unexpected iscsi volume name '%s'"),
                        def->src->srcpool->volume);
@@ -31375,7 +31376,6 @@ virDomainDiskAddISCSIPoolSourceHost(virDomainDiskDefPtr def,
     ret = 0;
 
  cleanup:
-    virStringListFree(tokens);
     return ret;
 }