提交 824808dd 编写于 作者: K Kevin Wolf

block: Don't silently truncate node names

If the user passes a too long node name string, we silently truncate it
to fit into BlockDriverState.node_name, i.e. to 31 characters. Apart
from surprising the user when the node has a different name than
requested, this also bypasses the check for duplicate names, so that the
same name can be assigned to multiple nodes.

Fix this by just making too long node names an error.
Reported-by: NPeter Krempa <pkrempa@redhat.com>
Signed-off-by: NKevin Wolf <kwolf@redhat.com>
上级 bfcc224e
......@@ -1156,6 +1156,12 @@ static void bdrv_assign_node_name(BlockDriverState *bs,
goto out;
}
/* Make sure that the node name isn't truncated */
if (strlen(node_name) >= sizeof(bs->node_name)) {
error_setg(errp, "Node name too long");
goto out;
}
/* copy node name into the bs and insert it into the graph list */
pstrcpy(bs->node_name, sizeof(bs->node_name), node_name);
QTAILQ_INSERT_TAIL(&graph_bdrv_states, bs, node_list);
......
......@@ -99,6 +99,21 @@ run_qemu -drive file="$TEST_IMG",driver=foo
run_qemu -drive file="$TEST_IMG",driver=raw,format=qcow2
run_qemu -drive file="$TEST_IMG",driver=qcow2,format=qcow2
echo
echo === Node names ===
echo
# Maximum length: 31 characters
run_qemu -drive file="$TEST_IMG",node-name=x123456789012345678901234567890
run_qemu -drive file="$TEST_IMG",node-name=x1234567890123456789012345678901
# First character must be alphabetic
# Following characters alphanumeric or -._
run_qemu -drive file="$TEST_IMG",node-name=All-Types.of_all0wed_chars
run_qemu -drive file="$TEST_IMG",node-name=123foo
run_qemu -drive file="$TEST_IMG",node-name=_foo
run_qemu -drive file="$TEST_IMG",node-name=foo#12
echo
echo === Device without drive ===
echo
......
......@@ -47,6 +47,29 @@ Testing: -drive file=TEST_DIR/t.qcow2,driver=qcow2,format=qcow2
QEMU_PROG: -drive file=TEST_DIR/t.qcow2,driver=qcow2,format=qcow2: Cannot specify both 'driver' and 'format'
=== Node names ===
Testing: -drive file=TEST_DIR/t.qcow2,node-name=x123456789012345678901234567890
QEMU X.Y.Z monitor - type 'help' for more information
(qemu) quit
Testing: -drive file=TEST_DIR/t.qcow2,node-name=x1234567890123456789012345678901
QEMU_PROG: -drive file=TEST_DIR/t.qcow2,node-name=x1234567890123456789012345678901: Node name too long
Testing: -drive file=TEST_DIR/t.qcow2,node-name=All-Types.of_all0wed_chars
QEMU X.Y.Z monitor - type 'help' for more information
(qemu) quit
Testing: -drive file=TEST_DIR/t.qcow2,node-name=123foo
QEMU_PROG: -drive file=TEST_DIR/t.qcow2,node-name=123foo: Invalid node name
Testing: -drive file=TEST_DIR/t.qcow2,node-name=_foo
QEMU_PROG: -drive file=TEST_DIR/t.qcow2,node-name=_foo: Invalid node name
Testing: -drive file=TEST_DIR/t.qcow2,node-name=foo#12
QEMU_PROG: -drive file=TEST_DIR/t.qcow2,node-name=foo#12: Invalid node name
=== Device without drive ===
Testing: -device VIRTIO_SCSI -device scsi-hd
......
......@@ -47,6 +47,29 @@ Testing: -drive file=TEST_DIR/t.qcow2,driver=qcow2,format=qcow2
QEMU_PROG: -drive file=TEST_DIR/t.qcow2,driver=qcow2,format=qcow2: Cannot specify both 'driver' and 'format'
=== Node names ===
Testing: -drive file=TEST_DIR/t.qcow2,node-name=x123456789012345678901234567890
QEMU X.Y.Z monitor - type 'help' for more information
(qemu) quit
Testing: -drive file=TEST_DIR/t.qcow2,node-name=x1234567890123456789012345678901
QEMU_PROG: -drive file=TEST_DIR/t.qcow2,node-name=x1234567890123456789012345678901: Node name too long
Testing: -drive file=TEST_DIR/t.qcow2,node-name=All-Types.of_all0wed_chars
QEMU X.Y.Z monitor - type 'help' for more information
(qemu) quit
Testing: -drive file=TEST_DIR/t.qcow2,node-name=123foo
QEMU_PROG: -drive file=TEST_DIR/t.qcow2,node-name=123foo: Invalid node name
Testing: -drive file=TEST_DIR/t.qcow2,node-name=_foo
QEMU_PROG: -drive file=TEST_DIR/t.qcow2,node-name=_foo: Invalid node name
Testing: -drive file=TEST_DIR/t.qcow2,node-name=foo#12
QEMU_PROG: -drive file=TEST_DIR/t.qcow2,node-name=foo#12: Invalid node name
=== Device without drive ===
Testing: -device VIRTIO_SCSI -device scsi-hd
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册