examples/vm_power_manager: fix string overflow

Message ID 20190410145431.35269-1-reshma.pattan@intel.com (mailing list archive)
State Accepted, archived
Delegated to: Thomas Monjalon
Headers
Series examples/vm_power_manager: fix string overflow |

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/Intel-compilation success Compilation OK
ci/intel-Performance-Testing success Performance Testing PASS
ci/mellanox-Performance-Testing success Performance Testing PASS

Commit Message

Pattan, Reshma April 10, 2019, 2:54 p.m. UTC
  Use strlcpy instead of strcpy to fix string overflow.

Coverity issue: 337671
Fixes: a63504a90f ("examples/power: add JSON string handling")
CC: david.hunt@intel.com
CC: stable@dpdk.org

Signed-off-by: Reshma Pattan <reshma.pattan@intel.com>
---
 examples/vm_power_manager/channel_monitor.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
  

Comments

Hunt, David April 15, 2019, 2:45 p.m. UTC | #1
On 10/4/2019 3:54 PM, Reshma Pattan wrote:
> Use strlcpy instead of strcpy to fix string overflow.
>
> Coverity issue: 337671
> Fixes: a63504a90f ("examples/power: add JSON string handling")
> CC: david.hunt@intel.com
> CC: stable@dpdk.org
>
> Signed-off-by: Reshma Pattan <reshma.pattan@intel.com>
> ---
>   examples/vm_power_manager/channel_monitor.c | 3 ++-
>   1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/examples/vm_power_manager/channel_monitor.c b/examples/vm_power_manager/channel_monitor.c
> index 74df0fe20..0b44a74b5 100644
> --- a/examples/vm_power_manager/channel_monitor.c
> +++ b/examples/vm_power_manager/channel_monitor.c
> @@ -159,7 +159,8 @@ parse_json_to_pkt(json_t *element, struct channel_packet *pkt)
>   			if (ret)
>   				return ret;
>   		} else if (!strcmp(key, "name")) {
> -			strcpy(pkt->vm_name, json_string_value(value));
> +			strlcpy(pkt->vm_name, json_string_value(value),
> +					sizeof(pkt->vm_name));
>   		} else if (!strcmp(key, "command")) {
>   			char command[32];
>   			strlcpy(command, json_string_value(value), 32);


Acked-by: David Hunt <david.hunt@intel.com>
  
Thomas Monjalon April 22, 2019, 9:09 p.m. UTC | #2
15/04/2019 16:45, Hunt, David:
> On 10/4/2019 3:54 PM, Reshma Pattan wrote:
> > Use strlcpy instead of strcpy to fix string overflow.
> >
> > Coverity issue: 337671
> > Fixes: a63504a90f ("examples/power: add JSON string handling")
> > CC: david.hunt@intel.com
> > CC: stable@dpdk.org
> >
> > Signed-off-by: Reshma Pattan <reshma.pattan@intel.com>
> 
> Acked-by: David Hunt <david.hunt@intel.com>

Applied, thanks
  

Patch

diff --git a/examples/vm_power_manager/channel_monitor.c b/examples/vm_power_manager/channel_monitor.c
index 74df0fe20..0b44a74b5 100644
--- a/examples/vm_power_manager/channel_monitor.c
+++ b/examples/vm_power_manager/channel_monitor.c
@@ -159,7 +159,8 @@  parse_json_to_pkt(json_t *element, struct channel_packet *pkt)
 			if (ret)
 				return ret;
 		} else if (!strcmp(key, "name")) {
-			strcpy(pkt->vm_name, json_string_value(value));
+			strlcpy(pkt->vm_name, json_string_value(value),
+					sizeof(pkt->vm_name));
 		} else if (!strcmp(key, "command")) {
 			char command[32];
 			strlcpy(command, json_string_value(value), 32);