conf: Move disk vendor and product pritability check to domain_validate

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
This commit is contained in:
Peter Krempa 2021-04-14 09:31:05 +02:00
parent e2a69d7641
commit fc2e60fda7
2 changed files with 27 additions and 22 deletions

View File

@ -9433,22 +9433,10 @@ virDomainDiskDefParseXML(virDomainXMLOption *xmlopt,
virXMLNodeNameEqual(cur, "vendor")) { virXMLNodeNameEqual(cur, "vendor")) {
if (!(vendor = virXMLNodeContentString(cur))) if (!(vendor = virXMLNodeContentString(cur)))
return NULL; return NULL;
if (!virStringIsPrintable(vendor)) {
virReportError(VIR_ERR_XML_ERROR, "%s",
_("disk vendor is not printable string"));
return NULL;
}
} else if (!product && } else if (!product &&
virXMLNodeNameEqual(cur, "product")) { virXMLNodeNameEqual(cur, "product")) {
if (!(product = virXMLNodeContentString(cur))) if (!(product = virXMLNodeContentString(cur)))
return NULL; return NULL;
if (!virStringIsPrintable(product)) {
virReportError(VIR_ERR_XML_ERROR, "%s",
_("disk product is not printable string"));
return NULL;
}
} else if (virXMLNodeNameEqual(cur, "boot")) { } else if (virXMLNodeNameEqual(cur, "boot")) {
/* boot is parsed as part of virDomainDeviceInfoParseXML */ /* boot is parsed as part of virDomainDeviceInfoParseXML */
} else if ((flags & VIR_DOMAIN_DEF_PARSE_STATUS) && } else if ((flags & VIR_DOMAIN_DEF_PARSE_STATUS) &&

View File

@ -27,6 +27,7 @@
#include "virconftypes.h" #include "virconftypes.h"
#include "virlog.h" #include "virlog.h"
#include "virutil.h" #include "virutil.h"
#include "virstring.h"
#define VIR_FROM_THIS VIR_FROM_DOMAIN #define VIR_FROM_THIS VIR_FROM_DOMAIN
@ -607,18 +608,34 @@ virDomainDiskDefValidate(const virDomainDef *def,
return -1; return -1;
} }
if (disk->vendor && strlen(disk->vendor) > VENDOR_LEN) { if (disk->vendor) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, if (!virStringIsPrintable(disk->vendor)) {
_("disk vendor is more than %d characters"), virReportError(VIR_ERR_XML_ERROR, "%s",
VENDOR_LEN); _("disk vendor is not printable string"));
return -1; 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) { if (disk->product) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, if (!virStringIsPrintable(disk->product)) {
_("disk product is more than %d characters"), virReportError(VIR_ERR_XML_ERROR, "%s",
PRODUCT_LEN); _("disk product is not printable string"));
return -1; 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 && if (disk->device == VIR_DOMAIN_DISK_DEVICE_FLOPPY &&