[v4] app/testpmd: fix copying the name of the dynflag

Message ID 1580823586-144444-1-git-send-email-orika@mellanox.com (mailing list archive)
State Accepted, archived
Delegated to: Ferruh Yigit
Headers
Series [v4] app/testpmd: fix copying the name of the dynflag |

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/iol-nxp-Performance success Performance Testing PASS
ci/iol-testing success Testing PASS
ci/iol-mellanox-Performance success Performance Testing PASS
ci/Intel-compilation fail apply issues

Commit Message

Ori Kam Feb. 4, 2020, 1:39 p.m. UTC
  When working with testpmd and setting the dynflag name, we copy the
name given by the cmd to the dynflag name.

The issue is that the size of the dynflag name is smaller then the
string used by testpmd.

This commit solves this issue by checking that the length of the requested
flag name is not too long.

Coverity issue: 353610

Fixes: b57b66a97ebf ("app/testpmd: support mbuf dynamic flag")

Signed-off-by: Ori Kam <orika@mellanox.com>
---
V4:
 * Address ML comments
V3:
 * Fix style issue.
V2:
 * change to check the requested flag name.
---
 app/test-pmd/cmdline.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
  

Comments

Iremonger, Bernard Feb. 4, 2020, 2:39 p.m. UTC | #1
> -----Original Message-----
> From: Ori Kam <orika@mellanox.com>
> Sent: Tuesday, February 4, 2020 1:40 PM
> To: Lu, Wenzhuo <wenzhuo.lu@intel.com>; Wu, Jingjing
> <jingjing.wu@intel.com>; Iremonger, Bernard
> <bernard.iremonger@intel.com>
> Cc: dev@dpdk.org; orika@mellanox.com; Yigit, Ferruh
> <ferruh.yigit@intel.com>; viacheslavo@mellanox.com
> Subject: [PATCH v4] app/testpmd: fix copying the name of the dynflag
> 
> When working with testpmd and setting the dynflag name, we copy the
> name given by the cmd to the dynflag name.
> 
> The issue is that the size of the dynflag name is smaller then the string used
> by testpmd.
> 
> This commit solves this issue by checking that the length of the requested
> flag name is not too long.
> 
> Coverity issue: 353610
> 
> Fixes: b57b66a97ebf ("app/testpmd: support mbuf dynamic flag")
> 
> Signed-off-by: Ori Kam <orika@mellanox.com>

Acked-by: Bernard Iremonger <bernard.iremonger@intel.com>
  
Ferruh Yigit Feb. 4, 2020, 5:58 p.m. UTC | #2
On 2/4/2020 2:39 PM, Iremonger, Bernard wrote:
>> -----Original Message-----
>> From: Ori Kam <orika@mellanox.com>
>> Sent: Tuesday, February 4, 2020 1:40 PM
>> To: Lu, Wenzhuo <wenzhuo.lu@intel.com>; Wu, Jingjing
>> <jingjing.wu@intel.com>; Iremonger, Bernard
>> <bernard.iremonger@intel.com>
>> Cc: dev@dpdk.org; orika@mellanox.com; Yigit, Ferruh
>> <ferruh.yigit@intel.com>; viacheslavo@mellanox.com
>> Subject: [PATCH v4] app/testpmd: fix copying the name of the dynflag
>>
>> When working with testpmd and setting the dynflag name, we copy the
>> name given by the cmd to the dynflag name.
>>
>> The issue is that the size of the dynflag name is smaller then the string used
>> by testpmd.
>>
>> This commit solves this issue by checking that the length of the requested
>> flag name is not too long.
>>
>> Coverity issue: 353610
>>
>> Fixes: b57b66a97ebf ("app/testpmd: support mbuf dynamic flag")
>>
>> Signed-off-by: Ori Kam <orika@mellanox.com>
> 
> Acked-by: Bernard Iremonger <bernard.iremonger@intel.com>
> 

Applied to dpdk-next-net/master, thanks.
  

Patch

diff --git a/app/test-pmd/cmdline.c b/app/test-pmd/cmdline.c
index dab22bc..45602cc 100644
--- a/app/test-pmd/cmdline.c
+++ b/app/test-pmd/cmdline.c
@@ -18867,14 +18867,18 @@  struct cmd_config_tx_dynf_specific_result {
 		return;
 	flag = rte_mbuf_dynflag_lookup(res->name, NULL);
 	if (flag <= 0) {
-		strcpy(desc_flag.name, res->name);
+		if (strlcpy(desc_flag.name, res->name,
+			    RTE_MBUF_DYN_NAMESIZE) >= RTE_MBUF_DYN_NAMESIZE) {
+			printf("Flag name too long\n");
+			return;
+		}
 		desc_flag.flags = 0;
 		flag = rte_mbuf_dynflag_register(&desc_flag);
 		if (flag < 0) {
 			printf("Can't register flag\n");
 			return;
 		}
-		strcpy(dynf_names[flag], res->name);
+		strcpy(dynf_names[flag], desc_flag.name);
 	}
 	old_port_flags = ports[res->port_id].mbuf_dynf;
 	if (!strcmp(res->value, "set")) {