hv: replace strcpy_s with strncpy_s

They're some duplicated and strcpy_s is not safety as strncpy_s.

Tracked-On: #861
Signed-off-by: Li, Fei1 <fei1.li@intel.com>
Acked-by: Eddie Dong <eddie.dong@intel.com>
Reviewed-by: Huang, Yonghua <yonghua.huang@intel.com>
This commit is contained in:
Li, Fei1 2018-12-12 20:13:11 +08:00 committed by wenlingz
parent 07427b4ca9
commit 29c8494fd0
3 changed files with 19 additions and 20 deletions

View File

@ -114,13 +114,12 @@ static void parse_other_modules(struct acrn_vm *vm,
/*copy boot args to load addr, set src=load addr*/
if (copy_once != 0) {
copy_once = 0;
(void)strcpy_s(load_addr, MEM_2K, (const
char *)vm->sw.linux_info.bootargs_src_addr);
(void)strncpy_s(load_addr, MEM_2K, (const char *)vm->sw.linux_info.bootargs_src_addr,
vm->sw.linux_info.bootargs_size);
vm->sw.linux_info.bootargs_src_addr = load_addr;
}
(void)strcpy_s(load_addr + args_size,
100U, dyn_bootargs);
(void)strncpy_s(load_addr + args_size, 100U, dyn_bootargs, 100U);
vm->sw.linux_info.bootargs_size =
strnlen_s(load_addr, MEM_2K);

View File

@ -127,7 +127,7 @@ int32_t general_sw_loader(struct acrn_vm *vm)
hva = gpa2hva(vm, (uint64_t)linux_info->bootargs_load_addr);
/* Copy Guest OS bootargs to its load location */
(void)strcpy_s((char *)hva, MEM_2K, linux_info->bootargs_src_addr);
(void)strncpy_s((char *)hva, MEM_2K, linux_info->bootargs_src_addr, linux_info->bootargs_size);
/* add "hugepagesz=1G hugepages=x" to cmdline for 1G hugepage
* reserving. Current strategy is "total_mem_size in Giga -
@ -143,7 +143,7 @@ int32_t general_sw_loader(struct acrn_vm *vm)
#endif
if (reserving_1g_pages > 0) {
snprintf(dyn_bootargs, 100U, " hugepagesz=1G hugepages=%d", reserving_1g_pages);
(void)strcpy_s((char *)hva + linux_info->bootargs_size, 100U, dyn_bootargs);
(void)strncpy_s((char *)hva + linux_info->bootargs_size, 100U, dyn_bootargs, 100U);
}
}

View File

@ -328,7 +328,7 @@ static int32_t shell_process_cmd(const char *p_input_line)
/* Copy the input line INTo an argument string to become part of the
* argument vector.
*/
(void)strcpy_s(&cmd_argv_str[0], SHELL_CMD_MAX_LEN, p_input_line);
(void)strncpy_s(&cmd_argv_str[0], SHELL_CMD_MAX_LEN, p_input_line, SHELL_CMD_MAX_LEN);
cmd_argv_str[SHELL_CMD_MAX_LEN] = 0;
/* Build the argv vector from the string. The first argument in the
@ -525,16 +525,16 @@ static int32_t shell_list_vm(__unused int32_t argc, __unused char **argv)
}
switch (vm->state) {
case VM_CREATED:
(void)strcpy_s(state, 32U, "Created");
(void)strncpy_s(state, 32U, "Created", 32U);
break;
case VM_STARTED:
(void)strcpy_s(state, 32U, "Started");
(void)strncpy_s(state, 32U, "Started", 32U);
break;
case VM_PAUSED:
(void)strcpy_s(state, 32U, "Paused");
(void)strncpy_s(state, 32U, "Paused", 32U);
break;
default:
(void)strcpy_s(state, 32U, "Unknown");
(void)strncpy_s(state, 32U, "Unknown", 32U);
break;
}
/* Create output string consisting of VM name and VM id
@ -570,19 +570,19 @@ static int32_t shell_list_vcpu(__unused int32_t argc, __unused char **argv)
foreach_vcpu(i, vm, vcpu) {
switch (vcpu->state) {
case VCPU_INIT:
(void)strcpy_s(state, 32U, "Init");
(void)strncpy_s(state, 32U, "Init", 32U);
break;
case VCPU_PAUSED:
(void)strcpy_s(state, 32U, "Paused");
(void)strncpy_s(state, 32U, "Paused", 32U);
break;
case VCPU_RUNNING:
(void)strcpy_s(state, 32U, "Running");
(void)strncpy_s(state, 32U, "Running", 32U);
break;
case VCPU_ZOMBIE:
(void)strcpy_s(state, 32U, "Zombie");
(void)strncpy_s(state, 32U, "Zombie", 32U);
break;
default:
(void)strcpy_s(state, 32U, "Unknown");
(void)strncpy_s(state, 32U, "Unknown", 32U);
}
/* Create output string consisting of VM name
* and VM id
@ -908,7 +908,7 @@ static void get_entry_info(const struct ptirq_remapping_info *entry, char *type,
{
if (is_entry_active(entry)) {
if (entry->intr_type == PTDEV_INTR_MSI) {
(void)strcpy_s(type, 16U, "MSI");
(void)strncpy_s(type, 16U, "MSI", 16U);
*dest = (entry->msi.pmsi_addr & 0xFF000U) >> PAGE_SHIFT;
if ((entry->msi.pmsi_data & APIC_TRIGMOD_LEVEL) != 0U) {
*lvl_tm = true;
@ -924,9 +924,9 @@ static void get_entry_info(const struct ptirq_remapping_info *entry, char *type,
union ioapic_rte rte;
if (entry->virt_sid.intx_id.src == PTDEV_VPIN_IOAPIC) {
(void)strcpy_s(type, 16U, "IOAPIC");
(void)strncpy_s(type, 16U, "IOAPIC", 16U);
} else {
(void)strcpy_s(type, 16U, "PIC");
(void)strncpy_s(type, 16U, "PIC", 16U);
}
ioapic_get_rte(phys_irq, &rte);
*dest = rte.full >> IOAPIC_RTE_DEST_SHIFT;
@ -943,7 +943,7 @@ static void get_entry_info(const struct ptirq_remapping_info *entry, char *type,
*irq = entry->allocated_pirq;
*vector = irq_to_vector(entry->allocated_pirq);
} else {
(void)strcpy_s(type, 16U, "NONE");
(void)strncpy_s(type, 16U, "NONE", 16U);
*irq = IRQ_INVALID;
*vector = 0U;
*dest = 0UL;