From: Ján Tomko Date: Wed, 1 Nov 2023 14:18:24 +0000 (+0100) Subject: conf: virDomainDiskSourceFormat: check for srcpool presence correctly X-Git-Tag: v9.10.0-rc1~65 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=66e84b8a953c59d7248f62d514957cec61515eb7;p=thirdparty%2Flibvirt.git conf: virDomainDiskSourceFormat: check for srcpool presence correctly As a guard against programming errors, one part of the condition only dereferences srcpool if it exists, other one does not. Move the check up one level so that it actually has a chance to do something useful. Fixes: 19b1c0d31988a3a10c4694c10c27eb15c018f450 Signed-off-by: Ján Tomko Reviewed-by: Andrea Bolognani --- diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 428147fe44..27f6862067 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -22363,14 +22363,12 @@ virDomainDiskSourceFormat(virBuffer *buf, g_auto(virBuffer) attrBuf = VIR_BUFFER_INITIALIZER; g_auto(virBuffer) childBuf = VIR_BUFFER_INIT_CHILD(buf); - if (src->type == VIR_STORAGE_TYPE_VOLUME) { - if (src->srcpool) { - virBufferEscapeString(&attrBuf, " pool='%s'", src->srcpool->pool); - virBufferEscapeString(&attrBuf, " volume='%s'", src->srcpool->volume); - if (src->srcpool->mode) - virBufferAsprintf(&attrBuf, " mode='%s'", - virStorageSourcePoolModeTypeToString(src->srcpool->mode)); - } + if (src->type == VIR_STORAGE_TYPE_VOLUME && src->srcpool) { + virBufferEscapeString(&attrBuf, " pool='%s'", src->srcpool->pool); + virBufferEscapeString(&attrBuf, " volume='%s'", src->srcpool->volume); + if (src->srcpool->mode) + virBufferAsprintf(&attrBuf, " mode='%s'", + virStorageSourcePoolModeTypeToString(src->srcpool->mode)); if (flags & VIR_DOMAIN_DEF_FORMAT_VOLUME_TRANSLATED && src->srcpool->actualtype != VIR_STORAGE_TYPE_NONE) {