net/virtio-user: fix TAP name string termination
authorSebastian Basierski <sebastianx.basierski@intel.com>
Tue, 19 Sep 2017 11:41:04 +0000 (13:41 +0200)
committerYuanhan Liu <yliu@fridaylinux.org>
Tue, 10 Oct 2017 13:54:31 +0000 (15:54 +0200)
Fix calling strncpy with the a maximum size equal of destination
array size.

Coverity issue: 140732
Fixes: e3b434818bbb ("net/virtio-user: support kernel vhost")
Cc: stable@dpdk.org
Signed-off-by: Sebastian Basierski <sebastianx.basierski@intel.com>
Acked-by: Jianfeng Tan <jianfeng.tan@intel.com>
Acked-by: Yuanhan Liu <yliu@fridaylinux.org>
drivers/net/virtio/virtio_user/vhost_kernel_tap.c

index f585de8..689a5cf 100644 (file)
@@ -95,9 +95,9 @@ vhost_kernel_open_tap(char **p_ifname, int hdr_size, int req_mq)
                ifr.ifr_flags |= IFF_MULTI_QUEUE;
 
        if (*p_ifname)
-               strncpy(ifr.ifr_name, *p_ifname, IFNAMSIZ);
+               strncpy(ifr.ifr_name, *p_ifname, IFNAMSIZ - 1);
        else
-               strncpy(ifr.ifr_name, "tap%d", IFNAMSIZ);
+               strncpy(ifr.ifr_name, "tap%d", IFNAMSIZ - 1);
        if (ioctl(tapfd, TUNSETIFF, (void *)&ifr) == -1) {
                PMD_DRV_LOG(ERR, "TUNSETIFF failed: %s", strerror(errno));
                goto error;