[v3] examples/vm_power: fix strcpy buffer overrun
Checks
Commit Message
replace strcpy with strlcpy to prevent buffer overrun
With fix, attempting to use a VERY lonng vm name results in a nicely
truncated 32 character name rather than a segfault:
Setting VM Name to [sdfdsfsfsdffdsdsasdsadasdakjshd]
Using strlcpy rather than rte_strlcpy, as the rte_ version is only a
fallback.
As well as the fix in main.c, this patch also changes an occurrence of
rte_strlcpy in channel_manager.c and channel_monitor.c to strlcpy.
Fixes: 59287933a0bb ("examples/vm_power: add options to guest app")
Cc: stable@dpdk.org
Signed-off-by: David Hunt <david.hunt@intel.com>
Acked-by: Anatoly Burakov <anatoly.burakov@intel.com>
---
examples/vm_power_manager/channel_manager.c | 2 +-
examples/vm_power_manager/channel_monitor.c | 2 +-
examples/vm_power_manager/guest_cli/main.c | 2 +-
3 files changed, 3 insertions(+), 3 deletions(-)
Comments
16/07/2019 13:19, David Hunt:
> replace strcpy with strlcpy to prevent buffer overrun
> With fix, attempting to use a VERY lonng vm name results in a nicely
> truncated 32 character name rather than a segfault:
> Setting VM Name to [sdfdsfsfsdffdsdsasdsadasdakjshd]
>
> Using strlcpy rather than rte_strlcpy, as the rte_ version is only a
> fallback.
>
> As well as the fix in main.c, this patch also changes an occurrence of
> rte_strlcpy in channel_manager.c and channel_monitor.c to strlcpy.
>
> Fixes: 59287933a0bb ("examples/vm_power: add options to guest app")
> Cc: stable@dpdk.org
> Signed-off-by: David Hunt <david.hunt@intel.com>
> Acked-by: Anatoly Burakov <anatoly.burakov@intel.com>
Applied, thanks
@@ -588,7 +588,7 @@ add_host_channels(void)
goto error;
}
chan_infos[i] = chan_info;
- rte_strlcpy(chan_info->channel_path, socket_path,
+ strlcpy(chan_info->channel_path, socket_path,
sizeof(chan_info->channel_path));
if (setup_host_channel_info(&chan_info, i) < 0) {
@@ -309,7 +309,7 @@ parse_json_to_pkt(json_t *element, struct channel_packet *pkt,
vm_name);
return -1;
}
- rte_strlcpy(pkt->vm_name, vm_name, VM_MAX_NAME_SZ);
+ strlcpy(pkt->vm_name, vm_name, VM_MAX_NAME_SZ);
pkt->resource_id = resource_id;
}
return 0;
@@ -65,7 +65,7 @@ parse_args(int argc, char **argv)
switch (opt) {
/* portmask */
case 'n':
- strcpy(policy->vm_name, optarg);
+ strlcpy(policy->vm_name, optarg, VM_MAX_NAME_SZ);
printf("Setting VM Name to [%s]\n", policy->vm_name);
break;
case 'b':