Blame SOURCES/kvm-block-Don-t-silently-truncate-node-names.patch

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