From: Peter Krempa Date: Wed, 14 Apr 2021 07:31:05 +0000 (+0200) Subject: conf: Move disk vendor and product pritability check to domain_validate X-Git-Tag: v7.3.0-rc1~160 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=fc2e60fda714740d55fb0baaf65c47898215028f;p=thirdparty%2Flibvirt.git conf: Move disk vendor and product pritability check to domain_validate Signed-off-by: Peter Krempa Reviewed-by: Michal Privoznik --- diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index c8c0476a42..0738bf7f1f 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -9433,22 +9433,10 @@ virDomainDiskDefParseXML(virDomainXMLOption *xmlopt, virXMLNodeNameEqual(cur, "vendor")) { if (!(vendor = virXMLNodeContentString(cur))) return NULL; - - if (!virStringIsPrintable(vendor)) { - virReportError(VIR_ERR_XML_ERROR, "%s", - _("disk vendor is not printable string")); - return NULL; - } } else if (!product && virXMLNodeNameEqual(cur, "product")) { if (!(product = virXMLNodeContentString(cur))) return NULL; - - if (!virStringIsPrintable(product)) { - virReportError(VIR_ERR_XML_ERROR, "%s", - _("disk product is not printable string")); - return NULL; - } } else if (virXMLNodeNameEqual(cur, "boot")) { /* boot is parsed as part of virDomainDeviceInfoParseXML */ } else if ((flags & VIR_DOMAIN_DEF_PARSE_STATUS) && diff --git a/src/conf/domain_validate.c b/src/conf/domain_validate.c index 97fa218252..b2780b3562 100644 --- a/src/conf/domain_validate.c +++ b/src/conf/domain_validate.c @@ -27,6 +27,7 @@ #include "virconftypes.h" #include "virlog.h" #include "virutil.h" +#include "virstring.h" #define VIR_FROM_THIS VIR_FROM_DOMAIN @@ -607,18 +608,34 @@ virDomainDiskDefValidate(const virDomainDef *def, return -1; } - if (disk->vendor && strlen(disk->vendor) > VENDOR_LEN) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("disk vendor is more than %d characters"), - VENDOR_LEN); - return -1; + if (disk->vendor) { + if (!virStringIsPrintable(disk->vendor)) { + virReportError(VIR_ERR_XML_ERROR, "%s", + _("disk vendor is not printable string")); + return -1; + } + + if (strlen(disk->vendor) > VENDOR_LEN) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("disk vendor is more than %d characters"), + VENDOR_LEN); + return -1; + } } - if (disk->product && strlen(disk->product) > PRODUCT_LEN) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("disk product is more than %d characters"), - PRODUCT_LEN); - return -1; + if (disk->product) { + if (!virStringIsPrintable(disk->product)) { + virReportError(VIR_ERR_XML_ERROR, "%s", + _("disk product is not printable string")); + return -1; + } + + if (strlen(disk->product) > PRODUCT_LEN) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("disk product is more than %d characters"), + PRODUCT_LEN); + return -1; + } } if (disk->device == VIR_DOMAIN_DISK_DEVICE_FLOPPY &&