]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
conf: Move disk vendor and product pritability check to domain_validate
authorPeter Krempa <pkrempa@redhat.com>
Wed, 14 Apr 2021 07:31:05 +0000 (09:31 +0200)
committerPeter Krempa <pkrempa@redhat.com>
Mon, 19 Apr 2021 12:43:59 +0000 (14:43 +0200)
Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
src/conf/domain_conf.c
src/conf/domain_validate.c

index c8c0476a42bfb37f3f428590a87a57bdb7cf1275..0738bf7f1f81b7cc1d0ecd8ea36daf73d519c9e2 100644 (file)
@@ -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) &&
index 97fa2182529a31f156525071b1e32ec8ab51fec0..b2780b3562e4625311166df7098f768674d322e2 100644 (file)
@@ -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 &&