diff --git a/devicemodel/core/sw_load_bzimage.c b/devicemodel/core/sw_load_bzimage.c index f79e5da24..b6dbdda87 100644 --- a/devicemodel/core/sw_load_bzimage.c +++ b/devicemodel/core/sw_load_bzimage.c @@ -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)); } diff --git a/devicemodel/core/sw_load_vsbl.c b/devicemodel/core/sw_load_vsbl.c index 29963914f..2cf819857 100644 --- a/devicemodel/core/sw_load_vsbl.c +++ b/devicemodel/core/sw_load_vsbl.c @@ -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; diff --git a/devicemodel/core/vmmapi.c b/devicemodel/core/vmmapi.c index 00a0bca51..5fd8c5aec 100644 --- a/devicemodel/core/vmmapi.c +++ b/devicemodel/core/vmmapi.c @@ -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) diff --git a/devicemodel/hw/pci/virtio/virtio_hdcp.c b/devicemodel/hw/pci/virtio/virtio_hdcp.c index 6ce00fc56..3e44a93d6 100644 --- a/devicemodel/hw/pci/virtio/virtio_hdcp.c +++ b/devicemodel/hw/pci/virtio/virtio_hdcp.c @@ -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) { diff --git a/devicemodel/hw/pci/virtio/virtio_net.c b/devicemodel/hw/pci/virtio/virtio_net.c index 9ba4b86a8..30b2d29da 100644 --- a/devicemodel/hw/pci/virtio/virtio_net.c +++ b/devicemodel/hw/pci/virtio/virtio_net.c @@ -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; diff --git a/devicemodel/hw/platform/tpm/tpm.c b/devicemodel/hw/platform/tpm/tpm.c index 37a3f8e87..c613625c6 100644 --- a/devicemodel/hw/platform/tpm/tpm.c +++ b/devicemodel/hw/platform/tpm/tpm.c @@ -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;