[v3] app/testpmd: fix copying the name of the dynflag
diff mbox series

Message ID 1580418244-6462-1-git-send-email-orika@mellanox.com
State Changes Requested, archived
Delegated to: Ferruh Yigit
Headers show
Series
  • [v3] app/testpmd: fix copying the name of the dynflag
Related show

Checks

Context Check Description
ci/Intel-compilation fail apply issues
ci/travis-robot success Travis build: passed
ci/iol-testing success Testing PASS
ci/iol-mellanox-Performance success Performance Testing PASS
ci/iol-nxp-Performance success Performance Testing PASS
ci/checkpatch success coding style OK

Commit Message

Ori Kam Jan. 30, 2020, 9:04 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>
---
V3:
 * Fix style issue.

V2:
 * change to check the requested flag name.
---
 app/test-pmd/cmdline.c | 4 ++++
 1 file changed, 4 insertions(+)

Comments

Ferruh Yigit Jan. 31, 2020, 2:02 p.m. UTC | #1
On 1/30/2020 9:04 PM, Ori Kam wrote:
> 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>
> ---
> V3:
>  * Fix style issue.
> 
> V2:
>  * change to check the requested flag name.
> ---
>  app/test-pmd/cmdline.c | 4 ++++
>  1 file changed, 4 insertions(+)
> 
> diff --git a/app/test-pmd/cmdline.c b/app/test-pmd/cmdline.c
> index dab22bc..7ccc778 100644
> --- a/app/test-pmd/cmdline.c
> +++ b/app/test-pmd/cmdline.c
> @@ -18865,6 +18865,10 @@ struct cmd_config_tx_dynf_specific_result {
>  
>  	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
>  		return;
> +	if (strlen(res->name) > sizeof(desc_flag.name)) {

Shouldn't it be ">=" since 'strlen' doesn't count terminating char.
It would be safer to use 'strnlen'.

> +		printf("Flag name too long\n");
> +		return;
> +	}
>  	flag = rte_mbuf_dynflag_lookup(res->name, NULL);
>  	if (flag <= 0) {
>  		strcpy(desc_flag.name, res->name);

And it would be nice to use 'strlcpy' here, to be sure target string will be
null terminated.
Ori Kam Feb. 2, 2020, 9:12 a.m. UTC | #2
Hi Ferruh,
Thanks for your comments.

> -----Original Message-----
> From: Ferruh Yigit <ferruh.yigit@intel.com>
> Sent: Friday, January 31, 2020 4:02 PM
> To: Ori Kam <orika@mellanox.com>; Wenzhuo Lu <wenzhuo.lu@intel.com>;
> Jingjing Wu <jingjing.wu@intel.com>; Bernard Iremonger
> <bernard.iremonger@intel.com>
> Cc: dev@dpdk.org; Slava Ovsiienko <viacheslavo@mellanox.com>
> Subject: Re: [PATCH v3] app/testpmd: fix copying the name of the dynflag
> 
> On 1/30/2020 9:04 PM, Ori Kam wrote:
> > 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>
> > ---
> > V3:
> >  * Fix style issue.
> >
> > V2:
> >  * change to check the requested flag name.
> > ---
> >  app/test-pmd/cmdline.c | 4 ++++
> >  1 file changed, 4 insertions(+)
> >
> > diff --git a/app/test-pmd/cmdline.c b/app/test-pmd/cmdline.c
> > index dab22bc..7ccc778 100644
> > --- a/app/test-pmd/cmdline.c
> > +++ b/app/test-pmd/cmdline.c
> > @@ -18865,6 +18865,10 @@ struct cmd_config_tx_dynf_specific_result {
> >
> >  	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
> >  		return;
> > +	if (strlen(res->name) > sizeof(desc_flag.name)) {
> 
> Shouldn't it be ">=" since 'strlen' doesn't count terminating char.
> It would be safer to use 'strnlen'.
>

 
Will fix.

> > +		printf("Flag name too long\n");
> > +		return;
> > +	}
> >  	flag = rte_mbuf_dynflag_lookup(res->name, NULL);
> >  	if (flag <= 0) {
> >  		strcpy(desc_flag.name, res->name);
> 
> And it would be nice to use 'strlcpy' here, to be sure target string will be
> null terminated.

Will fix.
Iremonger, Bernard Feb. 4, 2020, 10:45 a.m. UTC | #3
Hi Ori,

<snip>

> > Subject: Re: [PATCH v3] app/testpmd: fix copying the name of the
> > dynflag
> >
> > On 1/30/2020 9:04 PM, Ori Kam wrote:
> > > 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>
> > > ---
> > > V3:
> > >  * Fix style issue.
> > >
> > > V2:
> > >  * change to check the requested flag name.
> > > ---
> > >  app/test-pmd/cmdline.c | 4 ++++
> > >  1 file changed, 4 insertions(+)
> > >
> > > diff --git a/app/test-pmd/cmdline.c b/app/test-pmd/cmdline.c index
> > > dab22bc..7ccc778 100644
> > > --- a/app/test-pmd/cmdline.c
> > > +++ b/app/test-pmd/cmdline.c
> > > @@ -18865,6 +18865,10 @@ struct cmd_config_tx_dynf_specific_result {
> > >
> > >  	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
> > >  		return;
> > > +	if (strlen(res->name) > sizeof(desc_flag.name)) {

Would it be simpler to use RTE_MBUF_DYN_NAMESIZE instead of sizeof(desc_flag.name) ?

> >
> > Shouldn't it be ">=" since 'strlen' doesn't count terminating char.
> > It would be safer to use 'strnlen'.
> >
> 
> 
> Will fix.
> 
> > > +		printf("Flag name too long\n");
> > > +		return;
> > > +	}
> > >  	flag = rte_mbuf_dynflag_lookup(res->name, NULL);
> > >  	if (flag <= 0) {
> > >  		strcpy(desc_flag.name, res->name);
> >
> > And it would be nice to use 'strlcpy' here, to be sure target string
> > will be null terminated.
> 
> Will fix.

Regards,

Bernard.
Ori Kam Feb. 4, 2020, 11:12 a.m. UTC | #4
Hi Bernard,


> -----Original Message-----
> From: Iremonger, Bernard <bernard.iremonger@intel.com>
> Sent: Tuesday, February 4, 2020 12:46 PM
> To: Ori Kam <orika@mellanox.com>; Yigit, Ferruh <ferruh.yigit@intel.com>;
> Lu, Wenzhuo <wenzhuo.lu@intel.com>; Wu, Jingjing <jingjing.wu@intel.com>
> Cc: dev@dpdk.org; Slava Ovsiienko <viacheslavo@mellanox.com>
> Subject: RE: [PATCH v3] app/testpmd: fix copying the name of the dynflag
> 
> Hi Ori,
> 
> <snip>
> 
> > > Subject: Re: [PATCH v3] app/testpmd: fix copying the name of the
> > > dynflag
> > >
> > > On 1/30/2020 9:04 PM, Ori Kam wrote:
> > > > 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>
> > > > ---
> > > > V3:
> > > >  * Fix style issue.
> > > >
> > > > V2:
> > > >  * change to check the requested flag name.
> > > > ---
> > > >  app/test-pmd/cmdline.c | 4 ++++
> > > >  1 file changed, 4 insertions(+)
> > > >
> > > > diff --git a/app/test-pmd/cmdline.c b/app/test-pmd/cmdline.c index
> > > > dab22bc..7ccc778 100644
> > > > --- a/app/test-pmd/cmdline.c
> > > > +++ b/app/test-pmd/cmdline.c
> > > > @@ -18865,6 +18865,10 @@ struct cmd_config_tx_dynf_specific_result {
> > > >
> > > >  	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
> > > >  		return;
> > > > +	if (strlen(res->name) > sizeof(desc_flag.name)) {
> 
> Would it be simpler to use RTE_MBUF_DYN_NAMESIZE instead of
> sizeof(desc_flag.name) ?
> 
I don't really care. I used the sizeof approach since it is more used in DPDK.
But If you wish I can move to define.

> > >
> > > Shouldn't it be ">=" since 'strlen' doesn't count terminating char.
> > > It would be safer to use 'strnlen'.
> > >
> >
> >
> > Will fix.
> >
> > > > +		printf("Flag name too long\n");
> > > > +		return;
> > > > +	}
> > > >  	flag = rte_mbuf_dynflag_lookup(res->name, NULL);
> > > >  	if (flag <= 0) {
> > > >  		strcpy(desc_flag.name, res->name);
> > >
> > > And it would be nice to use 'strlcpy' here, to be sure target string
> > > will be null terminated.
> >
> > Will fix.
> 
> Regards,
> 
> Bernard.
Iremonger, Bernard Feb. 4, 2020, 12:18 p.m. UTC | #5
Hi Ori,

<snip>


> > > > Subject: Re: [PATCH v3] app/testpmd: fix copying the name of the
> > > > dynflag
> > > >
> > > > On 1/30/2020 9:04 PM, Ori Kam wrote:
> > > > > 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>
> > > > > ---
> > > > > V3:
> > > > >  * Fix style issue.
> > > > >
> > > > > V2:
> > > > >  * change to check the requested flag name.
> > > > > ---
> > > > >  app/test-pmd/cmdline.c | 4 ++++
> > > > >  1 file changed, 4 insertions(+)
> > > > >
> > > > > diff --git a/app/test-pmd/cmdline.c b/app/test-pmd/cmdline.c
> > > > > index
> > > > > dab22bc..7ccc778 100644
> > > > > --- a/app/test-pmd/cmdline.c
> > > > > +++ b/app/test-pmd/cmdline.c
> > > > > @@ -18865,6 +18865,10 @@ struct
> > > > > cmd_config_tx_dynf_specific_result {
> > > > >
> > > > >  	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
> > > > >  		return;
> > > > > +	if (strlen(res->name) > sizeof(desc_flag.name)) {
> >
> > Would it be simpler to use RTE_MBUF_DYN_NAMESIZE instead of
> > sizeof(desc_flag.name) ?
> >
> I don't really care. I used the sizeof approach since it is more used in DPDK.
> But If you wish I can move to define.

For me it is simpler and clearer.

> 
> > > >
> > > > Shouldn't it be ">=" since 'strlen' doesn't count terminating char.

Not sure about ">="  as "=" does not allow space for terminating null.

> > > > It would be safer to use 'strnlen'.
> > > >
> > >
> > >
> > > Will fix.
> > >
> > > > > +		printf("Flag name too long\n");
> > > > > +		return;
> > > > > +	}
> > > > >  	flag = rte_mbuf_dynflag_lookup(res->name, NULL);
> > > > >  	if (flag <= 0) {
> > > > >  		strcpy(desc_flag.name, res->name);
> > > >
> > > > And it would be nice to use 'strlcpy' here, to be sure target
> > > > string will be null terminated.
> > >
> > > Will fix.
> >
Regards,

Bernard.
Ori Kam Feb. 4, 2020, 1:03 p.m. UTC | #6
> -----Original Message-----
> From: dev <dev-bounces@dpdk.org> On Behalf Of Iremonger, Bernard
> Sent: Tuesday, February 4, 2020 2:18 PM
> To: Ori Kam <orika@mellanox.com>; Yigit, Ferruh <ferruh.yigit@intel.com>;
> Lu, Wenzhuo <wenzhuo.lu@intel.com>; Wu, Jingjing <jingjing.wu@intel.com>
> Cc: dev@dpdk.org; Slava Ovsiienko <viacheslavo@mellanox.com>
> Subject: Re: [dpdk-dev] [PATCH v3] app/testpmd: fix copying the name of the
> dynflag
> 
> Hi Ori,
> 
> <snip>
> 
> 
> > > > > Subject: Re: [PATCH v3] app/testpmd: fix copying the name of the
> > > > > dynflag
> > > > >
> > > > > On 1/30/2020 9:04 PM, Ori Kam wrote:
> > > > > > 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>
> > > > > > ---
> > > > > > V3:
> > > > > >  * Fix style issue.
> > > > > >
> > > > > > V2:
> > > > > >  * change to check the requested flag name.
> > > > > > ---
> > > > > >  app/test-pmd/cmdline.c | 4 ++++
> > > > > >  1 file changed, 4 insertions(+)
> > > > > >
> > > > > > diff --git a/app/test-pmd/cmdline.c b/app/test-pmd/cmdline.c
> > > > > > index
> > > > > > dab22bc..7ccc778 100644
> > > > > > --- a/app/test-pmd/cmdline.c
> > > > > > +++ b/app/test-pmd/cmdline.c
> > > > > > @@ -18865,6 +18865,10 @@ struct
> > > > > > cmd_config_tx_dynf_specific_result {
> > > > > >
> > > > > >  	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
> > > > > >  		return;
> > > > > > +	if (strlen(res->name) > sizeof(desc_flag.name)) {
> > >
> > > Would it be simpler to use RTE_MBUF_DYN_NAMESIZE instead of
> > > sizeof(desc_flag.name) ?
> > >
> > I don't really care. I used the sizeof approach since it is more used in DPDK.
> > But If you wish I can move to define.
> 
> For me it is simpler and clearer.

O.K will change.

> 
> >
> > > > >
> > > > > Shouldn't it be ">=" since 'strlen' doesn't count terminating char.
> 
> Not sure about ">="  as "=" does not allow space for terminating null.
> 

In new version I changed it to be >= means error.

> > > > > It would be safer to use 'strnlen'.
> > > > >
> > > >
> > > >
> > > > Will fix.
> > > >
> > > > > > +		printf("Flag name too long\n");
> > > > > > +		return;
> > > > > > +	}
> > > > > >  	flag = rte_mbuf_dynflag_lookup(res->name, NULL);
> > > > > >  	if (flag <= 0) {
> > > > > >  		strcpy(desc_flag.name, res->name);
> > > > >
> > > > > And it would be nice to use 'strlcpy' here, to be sure target
> > > > > string will be null terminated.
> > > >
> > > > Will fix.
> > >
> Regards,
> 
> Bernard.

Patch
diff mbox series

diff --git a/app/test-pmd/cmdline.c b/app/test-pmd/cmdline.c
index dab22bc..7ccc778 100644
--- a/app/test-pmd/cmdline.c
+++ b/app/test-pmd/cmdline.c
@@ -18865,6 +18865,10 @@  struct cmd_config_tx_dynf_specific_result {
 
 	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
 		return;
+	if (strlen(res->name) > sizeof(desc_flag.name)) {
+		printf("Flag name too long\n");
+		return;
+	}
 	flag = rte_mbuf_dynflag_lookup(res->name, NULL);
 	if (flag <= 0) {
 		strcpy(desc_flag.name, res->name);