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

@ -318,7 +318,7 @@ acrn_sw_load_bzimage(struct vmctx *ctx)
ctx->bsp_regs.vcpu_id = 0;
if (with_bootargs) {
strcpy(ctx->baseaddr + BOOTARGS_LOAD_OFF(ctx), get_bootargs());
strncpy(ctx->baseaddr + BOOTARGS_LOAD_OFF(ctx), get_bootargs(), STR_LEN);
printf("SW_LOAD: bootargs copied to guest 0x%lx\n",
BOOTARGS_LOAD_OFF(ctx));
}

View File

@ -274,7 +274,7 @@ acrn_sw_load_vsbl(struct vmctx *ctx)
vsbl_para->acpi_table_size = get_acpi_table_length();
if (with_bootargs) {
strcpy(ctx->baseaddr + BOOTARGS_OFF(ctx), get_bootargs());
strncpy(ctx->baseaddr + BOOTARGS_OFF(ctx), get_bootargs(), STR_LEN);
vsbl_para->bootargs_address = BOOTARGS_OFF(ctx);
} else {
vsbl_para->bootargs_address = 0;

View File

@ -122,7 +122,7 @@ vm_create(const char *name, uint64_t req_buf)
ctx->fd = devfd;
ctx->lowmem_limit = 2 * GB;
ctx->name = (char *)(ctx + 1);
strcpy(ctx->name, name);
strncpy(ctx->name, name, strnlen(name, PATH_MAX) + 1);
/* Set trusty enable flag */
if (trusty_enabled)

View File

@ -347,7 +347,7 @@ connect_hdcp_daemon()
memset(&addr, 0, sizeof(addr));
addr.sun_family = AF_UNIX;
strcpy(addr.sun_path, HDCP_SDK_SOCKET_PATH);
strncpy(addr.sun_path, HDCP_SDK_SOCKET_PATH, sizeof(addr.sun_path));
ret = connect(fd, &addr, sizeof(struct sockaddr_un));
if (ret < 0) {

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;

View File

@ -50,7 +50,7 @@ int acrn_parse_vtpm2(char *arg)
sock_path = calloc(len + 1, 1);
if (!sock_path)
return -1;
strcpy(sock_path, value);
strncpy(sock_path, value, len + 1);
}
return 0;