]> xenbits.xensource.com Git - libvirt.git/commitdiff
qemu: block: Validate node-names for use with qemu
authorPeter Krempa <pkrempa@redhat.com>
Wed, 28 Mar 2018 07:04:49 +0000 (09:04 +0200)
committerPeter Krempa <pkrempa@redhat.com>
Mon, 7 May 2018 13:33:38 +0000 (15:33 +0200)
qemu declares node-name as a 32 byte buffer and silently truncates
anything longer than that. This is unacceptable for libvirt, so we need
to make sure that we won't ever supply a node-name exceeding 31 chars.

Add a function which will do the validation and use it to validate
storage-protocol node names.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: John Ferlan <jferlan@redhat.com>
src/qemu/qemu_block.c

index bc7bbfad3538896ca2e0da45f45695b173cdf9bc..213046da641ab4ec652bc277aea7d032334511cc 100644 (file)
 
 #define VIR_FROM_THIS VIR_FROM_QEMU
 
+/* qemu declares the buffer for node names as a 32 byte array */
+static const size_t qemuBlockNodeNameBufSize = 32;
+
+static int
+qemuBlockNodeNameValidate(const char *nn)
+{
+    if (!nn)
+        return 0;
+
+    if (strlen(nn) >= qemuBlockNodeNameBufSize) {
+        virReportError(VIR_ERR_INTERNAL_ERROR,
+                       _("node-name '%s' too long for qemu"), nn);
+        return -1;
+    }
+
+    return 0;
+}
+
 
 static int
 qemuBlockNamedNodesArrayToHash(size_t pos ATTRIBUTE_UNUSED,
@@ -1107,7 +1125,8 @@ qemuBlockStorageSourceGetBackendProps(virStorageSourcePtr src,
         break;
     }
 
-    if (virJSONValueObjectAdd(fileprops, "S:node-name", src->nodestorage, NULL) < 0) {
+    if (qemuBlockNodeNameValidate(src->nodestorage) < 0 ||
+        virJSONValueObjectAdd(fileprops, "S:node-name", src->nodestorage, NULL) < 0) {
         virJSONValueFree(fileprops);
         return NULL;
     }