From 101cfb965083d6ad1185efeff758005f5847524d Mon Sep 17 00:00:00 2001 From: Wei Liu Date: Thu, 4 Apr 2024 16:58:11 +0000 Subject: [PATCH] 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 --- virtio-devices/src/vhost_user/fs.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/virtio-devices/src/vhost_user/fs.rs b/virtio-devices/src/vhost_user/fs.rs index 4c6ca0c7b..10c39cb69 100644 --- a/virtio-devices/src/vhost_user/fs.rs +++ b/virtio-devices/src/vhost_user/fs.rs @@ -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; (