dm: use strncpy to replace strcpy

Tracked-On: #2133
Signed-off-by: Shuo A Liu <shuo.a.liu@intel.com>
Reviewed-by: Yonghua Huang <yonghua.huang@intel.com>
This commit is contained in:
Shuo A Liu
2018-12-25 11:03:51 +08:00
committed by wenlingz
parent b3ad44d4c1
commit 4b3ebf69c7
6 changed files with 9 additions and 9 deletions

View File

@@ -653,19 +653,19 @@ virtio_net_tap_open(char *devname)
return -1;
}
strcpy(devname, ifr.ifr_name);
strncpy(devname, ifr.ifr_name, IFNAMSIZ);
return tunfd;
}
static void
virtio_net_tap_setup(struct virtio_net *net, char *devname)
{
char tbuf[80 + 5]; /* room for "acrn_" prefix */
char tbuf[IFNAMSIZ];
int vhost_fd = -1;
int rc;
rc = snprintf(tbuf, strnlen(devname, 79) + 6, "acrn_%s", devname);
if (rc < 0 || rc >= 85) /* give warning if error or truncation happens */
rc = snprintf(tbuf, IFNAMSIZ, "acrn_%s", devname);
if (rc < 0 || rc >= IFNAMSIZ) /* give warning if error or truncation happens */
WPRINTF(("Fail to set tap device name %s\n", tbuf));
net->virtio_net_rx = virtio_net_tap_rx;