virtio-devices: fs: cap the tag copy length

The caller shouldn't pass in an &str that's too long. This is a
precaution if something goes wrong in the caller.

Signed-off-by: Wei Liu <liuwe@microsoft.com>
This commit is contained in:
Wei Liu 2024-04-04 16:58:11 +00:00 committed by Liu Wei
parent 11c593e3b9
commit 101cfb9650

View File

@ -399,7 +399,12 @@ impl Fs {
// Create virtio-fs device configuration.
let mut config = VirtioFsConfig::default();
let tag_bytes_slice = tag.as_bytes();
config.tag[..tag_bytes_slice.len()].copy_from_slice(tag_bytes_slice);
let len = if tag_bytes_slice.len() < config.tag.len() {
tag_bytes_slice.len()
} else {
config.tag.len()
};
config.tag[..len].copy_from_slice(tag_bytes_slice[..len].as_ref());
config.num_request_queues = req_num_queues as u32;
(