Commit 05755b29 authored by Andre Przywara's avatar Andre Przywara Committed by Will Deacon
Browse files

virtio: use strlcpy



GCC 8.x complains about improper usage of strncpy in virtio/net.c and
virtio/scsi.c:
In function 'virtio_scsi_init_one',
    inlined from 'virtio_scsi_init' at virtio/scsi.c:285:7:
virtio/scsi.c:247:2: error: 'strncpy' specified bound 224 equals destination size [-Werror=stringop-truncation]
  strncpy((char *)&sdev->target.vhost_wwpn, disk->wwpn, sizeof(sdev->target.vhost_wwpn));
  ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Fix this and the other occurences in virtio/ by using strlcpy instead
of strncpy.
Signed-off-by: Andre Przywara's avatarAndre Przywara <andre.przywara@arm.com>
Signed-off-by: default avatarWill Deacon <will.deacon@arm.com>
parent 266a0ed4
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
#include "kvm/uip.h" #include "kvm/uip.h"
#include "kvm/guest_compat.h" #include "kvm/guest_compat.h"
#include "kvm/iovec.h" #include "kvm/iovec.h"
#include "kvm/strbuf.h"
#include <linux/vhost.h> #include <linux/vhost.h>
#include <linux/virtio_net.h> #include <linux/virtio_net.h>
...@@ -283,12 +284,12 @@ static int virtio_net_request_tap(struct net_dev *ndev, struct ifreq *ifr, ...@@ -283,12 +284,12 @@ static int virtio_net_request_tap(struct net_dev *ndev, struct ifreq *ifr,
memset(ifr, 0, sizeof(*ifr)); memset(ifr, 0, sizeof(*ifr));
ifr->ifr_flags = IFF_TAP | IFF_NO_PI | IFF_VNET_HDR; ifr->ifr_flags = IFF_TAP | IFF_NO_PI | IFF_VNET_HDR;
if (tapname) if (tapname)
strncpy(ifr->ifr_name, tapname, sizeof(ifr->ifr_name)); strlcpy(ifr->ifr_name, tapname, sizeof(ifr->ifr_name));
ret = ioctl(ndev->tap_fd, TUNSETIFF, ifr); ret = ioctl(ndev->tap_fd, TUNSETIFF, ifr);
if (ret >= 0) if (ret >= 0)
strncpy(ndev->tap_name, ifr->ifr_name, sizeof(ndev->tap_name)); strlcpy(ndev->tap_name, ifr->ifr_name, sizeof(ndev->tap_name));
return ret; return ret;
} }
......
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
#include "kvm/guest_compat.h" #include "kvm/guest_compat.h"
#include "kvm/virtio-pci.h" #include "kvm/virtio-pci.h"
#include "kvm/virtio.h" #include "kvm/virtio.h"
#include "kvm/strbuf.h"
#include <linux/kernel.h> #include <linux/kernel.h>
#include <linux/virtio_scsi.h> #include <linux/virtio_scsi.h>
...@@ -255,7 +256,7 @@ static int virtio_scsi_init_one(struct kvm *kvm, struct disk_image *disk) ...@@ -255,7 +256,7 @@ static int virtio_scsi_init_one(struct kvm *kvm, struct disk_image *disk)
}, },
.kvm = kvm, .kvm = kvm,
}; };
strncpy((char *)&sdev->target.vhost_wwpn, disk->wwpn, sizeof(sdev->target.vhost_wwpn)); strlcpy((char *)&sdev->target.vhost_wwpn, disk->wwpn, sizeof(sdev->target.vhost_wwpn));
sdev->target.vhost_tpgt = strtol(disk->tpgt, NULL, 0); sdev->target.vhost_tpgt = strtol(disk->tpgt, NULL, 0);
virtio_init(kvm, sdev, &sdev->vdev, &scsi_dev_virtio_ops, virtio_init(kvm, sdev, &sdev->vdev, &scsi_dev_virtio_ops,
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment