From 39a1710d9a757391e6ecfdd5e1d5abd359e5a153 Mon Sep 17 00:00:00 2001 Message-Id: <39a1710d9a757391e6ecfdd5e1d5abd359e5a153@dist-git> From: Peter Krempa Date: Wed, 19 Feb 2020 15:09:53 +0100 Subject: [PATCH] virDomainDiskAddISCSIPoolSourceHost: Sanitize handling of string list MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 Reviewed-by: Ján Tomko (cherry picked from commit c5b1c14379994369f5cb92bbb3da36d7d19150c2) https://bugzilla.redhat.com/show_bug.cgi?id=1804603 Message-Id: Reviewed-by: Ján Tomko --- src/conf/domain_conf.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 68d9ce9c4e..6973d97e1d 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -31174,7 +31174,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) { @@ -31195,10 +31196,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); @@ -31220,7 +31221,6 @@ virDomainDiskAddISCSIPoolSourceHost(virDomainDiskDefPtr def, ret = 0; cleanup: - virStringListFree(tokens); return ret; } -- 2.25.0