cryptospore / rpms / qemu-kvm

Forked from rpms/qemu-kvm 2 years ago
Clone
26ba25
From 1920bc35d149d2b28658e5354468df407c9799f1 Mon Sep 17 00:00:00 2001
26ba25
From: Kevin Wolf <kwolf@redhat.com>
26ba25
Date: Thu, 5 Jul 2018 16:47:51 +0200
26ba25
Subject: [PATCH 190/268] block: Don't silently truncate node names
26ba25
26ba25
RH-Author: Kevin Wolf <kwolf@redhat.com>
26ba25
Message-id: <20180705164751.15271-2-kwolf@redhat.com>
26ba25
Patchwork-id: 81234
26ba25
O-Subject: [RHV-7.6 qemu-kvm-rhev PATCH 1/1] block: Don't silently truncate node names
26ba25
Bugzilla: 1549654
26ba25
RH-Acked-by: Laurent Vivier <lvivier@redhat.com>
26ba25
RH-Acked-by: Max Reitz <mreitz@redhat.com>
26ba25
RH-Acked-by: John Snow <jsnow@redhat.com>
26ba25
26ba25
If the user passes a too long node name string, we silently truncate it
26ba25
to fit into BlockDriverState.node_name, i.e. to 31 characters. Apart
26ba25
from surprising the user when the node has a different name than
26ba25
requested, this also bypasses the check for duplicate names, so that the
26ba25
same name can be assigned to multiple nodes.
26ba25
26ba25
Fix this by just making too long node names an error.
26ba25
26ba25
Reported-by: Peter Krempa <pkrempa@redhat.com>
26ba25
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
26ba25
(cherry picked from commit 824808dd77821ceba05357cb1ee4069a6a95bebd)
26ba25
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
26ba25
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
26ba25
---
26ba25
 block.c                       |  6 ++++++
26ba25
 tests/qemu-iotests/051        | 15 +++++++++++++++
26ba25
 tests/qemu-iotests/051.out    | 23 +++++++++++++++++++++++
26ba25
 tests/qemu-iotests/051.pc.out | 23 +++++++++++++++++++++++
26ba25
 4 files changed, 67 insertions(+)
26ba25
26ba25
diff --git a/block.c b/block.c
26ba25
index afe30ca..0516284 100644
26ba25
--- a/block.c
26ba25
+++ b/block.c
26ba25
@@ -1140,6 +1140,12 @@ static void bdrv_assign_node_name(BlockDriverState *bs,
26ba25
         goto out;
26ba25
     }
26ba25
 
26ba25
+    /* Make sure that the node name isn't truncated */
26ba25
+    if (strlen(node_name) >= sizeof(bs->node_name)) {
26ba25
+        error_setg(errp, "Node name too long");
26ba25
+        goto out;
26ba25
+    }
26ba25
+
26ba25
     /* copy node name into the bs and insert it into the graph list */
26ba25
     pstrcpy(bs->node_name, sizeof(bs->node_name), node_name);
26ba25
     QTAILQ_INSERT_TAIL(&graph_bdrv_states, bs, node_list);
26ba25
diff --git a/tests/qemu-iotests/051 b/tests/qemu-iotests/051
26ba25
index 69d34eb..c5cc0ee 100755
26ba25
--- a/tests/qemu-iotests/051
26ba25
+++ b/tests/qemu-iotests/051
26ba25
@@ -100,6 +100,21 @@ run_qemu -drive file="$TEST_IMG",driver=raw,format=qcow2
26ba25
 run_qemu -drive file="$TEST_IMG",driver=qcow2,format=qcow2
26ba25
 
26ba25
 echo
26ba25
+echo === Node names ===
26ba25
+echo
26ba25
+
26ba25
+# Maximum length: 31 characters
26ba25
+run_qemu -drive file="$TEST_IMG",node-name=x123456789012345678901234567890
26ba25
+run_qemu -drive file="$TEST_IMG",node-name=x1234567890123456789012345678901
26ba25
+
26ba25
+# First character must be alphabetic
26ba25
+# Following characters alphanumeric or -._
26ba25
+run_qemu -drive file="$TEST_IMG",node-name=All-Types.of_all0wed_chars
26ba25
+run_qemu -drive file="$TEST_IMG",node-name=123foo
26ba25
+run_qemu -drive file="$TEST_IMG",node-name=_foo
26ba25
+run_qemu -drive file="$TEST_IMG",node-name=foo#12
26ba25
+
26ba25
+echo
26ba25
 echo === Device without drive ===
26ba25
 echo
26ba25
 
26ba25
diff --git a/tests/qemu-iotests/051.out b/tests/qemu-iotests/051.out
26ba25
index dd9846d..b727350 100644
26ba25
--- a/tests/qemu-iotests/051.out
26ba25
+++ b/tests/qemu-iotests/051.out
26ba25
@@ -47,6 +47,29 @@ Testing: -drive file=TEST_DIR/t.qcow2,driver=qcow2,format=qcow2
26ba25
 QEMU_PROG: -drive file=TEST_DIR/t.qcow2,driver=qcow2,format=qcow2: Cannot specify both 'driver' and 'format'
26ba25
 
26ba25
 
26ba25
+=== Node names ===
26ba25
+
26ba25
+Testing: -drive file=TEST_DIR/t.qcow2,node-name=x123456789012345678901234567890
26ba25
+QEMU X.Y.Z monitor - type 'help' for more information
26ba25
+(qemu) quit
26ba25
+
26ba25
+Testing: -drive file=TEST_DIR/t.qcow2,node-name=x1234567890123456789012345678901
26ba25
+QEMU_PROG: -drive file=TEST_DIR/t.qcow2,node-name=x1234567890123456789012345678901: Node name too long
26ba25
+
26ba25
+Testing: -drive file=TEST_DIR/t.qcow2,node-name=All-Types.of_all0wed_chars
26ba25
+QEMU X.Y.Z monitor - type 'help' for more information
26ba25
+(qemu) quit
26ba25
+
26ba25
+Testing: -drive file=TEST_DIR/t.qcow2,node-name=123foo
26ba25
+QEMU_PROG: -drive file=TEST_DIR/t.qcow2,node-name=123foo: Invalid node name
26ba25
+
26ba25
+Testing: -drive file=TEST_DIR/t.qcow2,node-name=_foo
26ba25
+QEMU_PROG: -drive file=TEST_DIR/t.qcow2,node-name=_foo: Invalid node name
26ba25
+
26ba25
+Testing: -drive file=TEST_DIR/t.qcow2,node-name=foo#12
26ba25
+QEMU_PROG: -drive file=TEST_DIR/t.qcow2,node-name=foo#12: Invalid node name
26ba25
+
26ba25
+
26ba25
 === Device without drive ===
26ba25
 
26ba25
 Testing: -device VIRTIO_SCSI -device scsi-hd
26ba25
diff --git a/tests/qemu-iotests/051.pc.out b/tests/qemu-iotests/051.pc.out
26ba25
index b01f9a9..e9257fe 100644
26ba25
--- a/tests/qemu-iotests/051.pc.out
26ba25
+++ b/tests/qemu-iotests/051.pc.out
26ba25
@@ -47,6 +47,29 @@ Testing: -drive file=TEST_DIR/t.qcow2,driver=qcow2,format=qcow2
26ba25
 QEMU_PROG: -drive file=TEST_DIR/t.qcow2,driver=qcow2,format=qcow2: Cannot specify both 'driver' and 'format'
26ba25
 
26ba25
 
26ba25
+=== Node names ===
26ba25
+
26ba25
+Testing: -drive file=TEST_DIR/t.qcow2,node-name=x123456789012345678901234567890
26ba25
+QEMU X.Y.Z monitor - type 'help' for more information
26ba25
+(qemu) quit
26ba25
+
26ba25
+Testing: -drive file=TEST_DIR/t.qcow2,node-name=x1234567890123456789012345678901
26ba25
+QEMU_PROG: -drive file=TEST_DIR/t.qcow2,node-name=x1234567890123456789012345678901: Node name too long
26ba25
+
26ba25
+Testing: -drive file=TEST_DIR/t.qcow2,node-name=All-Types.of_all0wed_chars
26ba25
+QEMU X.Y.Z monitor - type 'help' for more information
26ba25
+(qemu) quit
26ba25
+
26ba25
+Testing: -drive file=TEST_DIR/t.qcow2,node-name=123foo
26ba25
+QEMU_PROG: -drive file=TEST_DIR/t.qcow2,node-name=123foo: Invalid node name
26ba25
+
26ba25
+Testing: -drive file=TEST_DIR/t.qcow2,node-name=_foo
26ba25
+QEMU_PROG: -drive file=TEST_DIR/t.qcow2,node-name=_foo: Invalid node name
26ba25
+
26ba25
+Testing: -drive file=TEST_DIR/t.qcow2,node-name=foo#12
26ba25
+QEMU_PROG: -drive file=TEST_DIR/t.qcow2,node-name=foo#12: Invalid node name
26ba25
+
26ba25
+
26ba25
 === Device without drive ===
26ba25
 
26ba25
 Testing: -device VIRTIO_SCSI -device scsi-hd
26ba25
-- 
26ba25
1.8.3.1
26ba25