[PATCH 2/2] net/virtio: fix fortify memcpy warning
Stephen Hemminger
stephen at networkplumber.org
Tue May 21 03:01:04 CEST 2024
If fortify is enabled, it will generate a warning if memcpy
src is NULL even if size is zero. This happens if the MP message
sync is called with no file descriptors.
Bugzilla ID 1446
Fixes: 6a84c37e3975 ("net/virtio-user: add vhost-user adapter layer")
Signed-off-by: Stephen Hemminger <stephen at networkplumber.org>
---
drivers/net/virtio/virtio_user/vhost_user.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/drivers/net/virtio/virtio_user/vhost_user.c b/drivers/net/virtio/virtio_user/vhost_user.c
index 3c05ac9cc0..c10252506b 100644
--- a/drivers/net/virtio/virtio_user/vhost_user.c
+++ b/drivers/net/virtio/virtio_user/vhost_user.c
@@ -128,7 +128,8 @@ vhost_user_write(int fd, struct vhost_user_msg *msg, int *fds, int fd_num)
cmsg->cmsg_len = CMSG_LEN(fd_size);
cmsg->cmsg_level = SOL_SOCKET;
cmsg->cmsg_type = SCM_RIGHTS;
- memcpy(CMSG_DATA(cmsg), fds, fd_size);
+ if (fd_size > 0)
+ memcpy(CMSG_DATA(cmsg), fds, fd_size);
do {
r = sendmsg(fd, &msgh, 0);
--
2.43.0
More information about the dev
mailing list