fixup ip pipeline examples
cover fixup ip pipeline examples
Lots of little trivial bugs/typos here.
Let's not start users off with a bad example.
Stephen Hemminger (5):
examples_ip_pipeline: fix typo's
example_ip_pipeline: avoid strncpy issue
example_ip_pipeline: fix sizeof() on memcpy
examples_ip_pipeline: remove useless code
examples_ip_pipeline: fix possible string overrun
examples/ip_pipeline/app.h | 2 +- examples/ip_pipeline/config_parse.c | 5 +---- examples/ip_pipeline/config_parse_tm.c | 6 ++++-- examples/ip_pipeline/init.c | 7 ++++--- examples/ip_pipeline/pipeline/pipeline_common_fe.c | 2 +- examples/ip_pipeline/pipeline/pipeline_flow_classification.c | 3 +-- 6 files changed, 12 insertions(+), 13 deletions(-)
Signature · 1 line
2.1.4
PATCH 1/5 examples_ip_pipeline: fix typo's
Coverity found these as dead-code and/or copy-paste bugs.
--- examples/ip_pipeline/config_parse.c | 2 +- examples/ip_pipeline/config_parse_tm.c | 2 +- examples/ip_pipeline/pipeline/pipeline_flow_classification.c | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-)
examples/ip_pipeline/config_parse.c +1 -1
@@ -2238,7 +2238,7 @@ save_pipeline_params(struct app_params *app, FILE *f) }/* msgq_out */ -if (p->n_msgq_in) { +if (p->n_msgq_out) {uint32_t j;fprintf (f,"msgq_out =" );
examples/ip_pipeline/config_parse_tm.c +1 -1
@@ -399,7 +399,7 @@ tm_cfgfile_load(struct app_pktq_tm_params *tm)memset (tm->sched_subport_params,0 ,sizeof (tm->sched_subport_params));memset (tm->sched_pipe_profiles,0 ,sizeof (tm->sched_pipe_profiles)); -memset (&tm->sched_port_params,0 ,sizeof (tm->sched_pipe_profiles)); +memset (&tm->sched_port_params,0 ,sizeof (tm->sched_port_params));for (i =0 ; i <APP_MAX_SCHED_SUBPORTS *APP_MAX_SCHED_PIPES ; i++) tm->sched_pipe_to_profile[i] =-1 ;
examples/ip_pipeline/pipeline/pipeline_flow_classification.c +1 -1
@@ -442,7 +442,7 @@ app_pipeline_fc_add_bulk(struct app_params *app, flow_rsp =rte_malloc (NULL , n_keys *sizeof (struct pipeline_fc_add_bulk_flow_rsp ),RTE_CACHE_LINE_SIZE ); -if (flow_req ==NULL ) { +if (flow_rsq ==NULL ) {rte_free (flow_req);rte_free (new_flow);rte_free (signature);
Signature · 1 line
2.1.4
Re: [PATCH 1/5] examples_ip_pipeline: fix typo's
Quoted 67 lines
-----Original Message-----
From: Stephen Hemminger [mailto:[email protected]]
Sent: Tuesday, September 1, 2015 4:59 AM
To: Dumitrescu, Cristian
Cc: [email protected]; Stephen Hemminger
Subject: [PATCH 1/5]examples_ip_pipeline: fix typo'sCoverity found these as dead-code and/or copy-paste bugs.
Signed-off-by Stephen Hemminger <[email protected]>--- examples/ip_pipeline/config_parse.c | 2 +- examples/ip_pipeline/config_parse_tm.c | 2 +- examples/ip_pipeline/pipeline/pipeline_flow_classification.c | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-)examples/ip_pipeline/config_parse.c +1
-1@@ -2238,7 +2238,7 @@ save_pipeline_params(struct app_params *app, FILE *f) }/* msgq_out */ -if (p->n_msgq_in) { +if (p->n_msgq_out) {uint32_t j;examples/ip_pipeline/config_parse.c +0
-0fprintf (f,"msgq_out =" );examples/ip_pipeline/config_parse_tm.c +1
-1@@ -399,7 +399,7 @@ tm_cfgfile_load(struct app_pktq_tm_params *tm)memset (tm->sched_subport_params,0 ,sizeof (tm- >sched_subport_params));memset (tm->sched_pipe_profiles,0 ,sizeof (tm- >sched_pipe_profiles)); -memset (&tm->sched_port_params,0 ,sizeof (tm- >sched_pipe_profiles)); + memset(&tm->sched_port_params, 0, sizeof(tm-Quoted 1 line
sched_port_params));for (i = 0; i <
APP_MAX_SCHED_SUBPORTS*APP_MAX_SCHED_PIPES; i++)examples/ip_pipeline/config_parse_tm.c +0
-0tm->sched_pipe_to_profile[i] =-1 ;examples/ip_pipeline/pipeline/pipeline_flow_classification.c +1
-2@@ -442,7 +442,7 @@ app_pipeline_fc_add_bulk(struct app_params *app, flow_rsp =rte_malloc (NULL , n_keys *sizeof (struct pipeline_fc_add_bulk_flow_rsp ),RTE_CACHE_LINE_SIZE ); -if (flow_req ==NULL ) { +if (flow_rsq ==NULL ) {rte_free (flow_req);rte_free (new_flow);rte_free (signature); --
Quoted 1 line
2.1.4
PATCH 2/5 example_ip_pipeline: avoid strncpy issue
In reply to Stephen HemmingerIf name is so long that it fills buffer, then string would not be null terminated.
--- examples/ip_pipeline/config_parse_tm.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
examples/ip_pipeline/config_parse_tm.c +3 -1
@@ -354,7 +354,9 @@ tm_cfgfile_load_sched_subport( profile =atoi (entries[j].value);strncpy (name, entries[j].name, -sizeof (name)); +CFG_NAME_LEN -1 ); + name[CFG_NAME_LEN -1 ] ='\0' ; + n_tokens = rte_strsplit( &name[sizeof("pipe")], strnlen(name, CFG_NAME_LEN),
Signature · 1 line
2.1.4
Re: [PATCH 2/5] example_ip_pipeline: avoid strncpy issue
Quoted 33 lines
-----Original Message-----
From: Stephen Hemminger [mailto:[email protected]]
Sent: Tuesday, September 1, 2015 4:59 AM
To: Dumitrescu, Cristian
Cc: [email protected]; Stephen Hemminger
Subject: [PATCH 2/5]example_ip_pipeline: avoid strncpy issueIf name is so long that it fills buffer, then string would not be null terminated.
Signed-off-by Stephen Hemminger <[email protected]>--- examples/ip_pipeline/config_parse_tm.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)examples/ip_pipeline/config_parse_tm.c +3
-1@@ -354,7 +354,9 @@ tm_cfgfile_load_sched_subport( profile =atoi (entries[j].value);strncpy (name, entries[j].name, -sizeof (name)); +CFG_NAME_LEN -1 ); + name[CFG_NAME_LEN -1 ] ='\0' ; + n_tokens = rte_strsplit( &name[sizeof("pipe")], strnlen(name,
Quoted 3 lines
CFG_NAME_LEN),
--
2.1.4
Re: [PATCH 2/5] example_ip_pipeline: avoid strncpy issue
In reply to Stephen HemmingerQuoted 26 lines · Stephen Hemminger
If name is so long that it fills buffer, then string would not be null terminated.
Signed-off-by Stephen Hemminger <[email protected]>--- examples/ip_pipeline/config_parse_tm.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)examples/ip_pipeline/config_parse_tm.c +3
-1@@ -354,7 +354,9 @@ tm_cfgfile_load_sched_subport( profile =atoi (entries[j].value);strncpy (name, entries[j].name, -sizeof (name)); +CFG_NAME_LEN -1 ); + name[CFG_NAME_LEN -1 ] ='\0' ; + n_tokens = rte_strsplit( &name[sizeof("pipe")], strnlen(name, CFG_NAME_LEN),Signature · 1 line
2.1.4
Would using snprintf rather than strncpy be tidier? Would save having to worry about null termination at all.
/Bruce
PATCH 3/5 example_ip_pipeline: fix sizeof() on memcpy
In reply to Stephen HemmingerFound by Coverity:
Sizeof not portable (SIZEOF_MISMATCH)
suspicious_sizeof: Passing argument &app->cmds[app->n_cmds] of type cmdline_parse_ctx_t * and argument n_cmds * 8UL /* sizeof (cmdline_parse_ctx_t *) */ to function memcpy is suspicious.
In this case, sizeof (cmdline_parse_ctx_t *) is equal to sizeof (cmdline_parse_ctx_t), but this is not a portable assumption.
--- examples/ip_pipeline/init.c | 2 +- examples/ip_pipeline/pipeline/pipeline_common_fe.c | 2 +- examples/ip_pipeline/pipeline/pipeline_flow_classification.c | 1 - 3 files changed, 2 insertions(+), 3 deletions(-)
examples/ip_pipeline/init.c +1 -1
@@ -1325,7 +1325,7 @@ app_pipeline_type_cmd_push(struct app_params *app,/* Push pipeline commands into the application */ memcpy (&app->cmds[app->n_cmds], cmds, - n_cmds *sizeof (cmdline_parse_ctx_t *)); + n_cmds *sizeof (cmdline_parse_ctx_t));for (i =0 ; i < n_cmds; i++) app->cmds[app->n_cmds + i]->data = app;
examples/ip_pipeline/pipeline/pipeline_common_fe.c +1 -1
@@ -1321,7 +1321,7 @@ app_pipeline_common_cmd_push(struct app_params *app)/* Push pipeline commands into the application */ memcpy (&app->cmds[app->n_cmds], pipeline_common_cmds, - n_cmds *sizeof (cmdline_parse_ctx_t *)); + n_cmds *sizeof (cmdline_parse_ctx_t));for (i =0 ; i < n_cmds; i++) app->cmds[app->n_cmds + i]->data = app;
examples/ip_pipeline/pipeline/pipeline_flow_classification.c +0 -1
@@ -126,7 +126,6 @@ app_pipeline_fc_key_convert(struct pipeline_fc_key *key_in, {struct pkt_key_ipv6_5tuple *ipv6 = key_buffer; -memset (ipv6,0 ,64 ); ipv6->payload_length =0 ; ipv6->proto = key_in->key.ipv6_5tuple.proto; ipv6->hop_limit =0 ;
Signature · 1 line
2.1.4
Re: [PATCH 3/5] example_ip_pipeline: fix sizeof() on memcpy
Quoted 31 lines
-----Original Message-----
From: Stephen Hemminger [mailto:[email protected]]
Sent: Tuesday, September 1, 2015 4:59 AM
To: Dumitrescu, Cristian
Cc: [email protected]; Stephen Hemminger
Subject: [PATCH 3/5]example_ip_pipeline: fixsizeof()on memcpyFound by Coverity:
Sizeof not portable (SIZEOF_MISMATCH)
suspicious_sizeof: Passing argument &app->cmds[app->n_cmds] of typecmdline_parse_ctx_t* and argumentn_cmds* 8UL /* sizeof
(cmdline_parse_ctx_t*) */
to function memcpy is suspicious.
In this case, sizeof (cmdline_parse_ctx_t*) is equal to sizeof
(cmdline_parse_ctx_t),
but this is not a portable assumption.Signed-off-by Stephen Hemminger <[email protected]>--- examples/ip_pipeline/init.c | 2 +- examples/ip_pipeline/pipeline/pipeline_common_fe.c | 2 +- examples/ip_pipeline/pipeline/pipeline_flow_classification.c | 1 - 3 files changed, 2 insertions(+), 3 deletions(-)examples/ip_pipeline/init.c +0
-0
examples/ip_pipeline/init.c app_pipeline_type_cmd_push(struct app_params · line 1329
Quoted 6 lines
examples/ip_pipeline/init.c +1
-1@@ -1325,7 +1325,7 @@ app_pipeline_type_cmd_push(struct app_params *app,/* Push pipeline commands into the application */ memcpy (&app->cmds[app->n_cmds], cmds, - n_cmds *sizeof (cmdline_parse_ctx_t *)); + n_cmds *sizeof (cmdline_parse_ctx_t));
Actually no, as we are both the destination and the source of memcpy are array of pointers.
The source is a pipeline type, which is a static global data structure, so no issues with the life time of the data pointed to by the pointers.
Quoted 9 lines
examples/ip_pipeline/init.c +0
-0for (i =0 ; i < n_cmds; i++) app->cmds[app->n_cmds + i]->data = app;examples/ip_pipeline/pipeline/pipeline_common_fe.c +0
-0
examples/ip_pipeline/pipeline/pipeline_common_fe.c app_pipeline_common_cmd_push(struct · line 1325
Quoted 6 lines
examples/ip_pipeline/pipeline/pipeline_common_fe.c +1
-1@@ -1321,7 +1321,7 @@ app_pipeline_common_cmd_push(struct app_params *app) /* Push pipeline commands into the application */ memcpy(&app->cmds[app->n_cmds], pipeline_common_cmds, - n_cmds * sizeof(cmdline_parse_ctx_t *)); + n_cmds * sizeof(cmdline_parse_ctx_t));
Actually no, as we are both the destination and the source of memcpy are array of pointers.
The source is a pipeline type, which is a static global data structure, so no issues with the life time of the data pointed to by the pointers.
Quoted 9 lines
examples/ip_pipeline/pipeline/pipeline_common_fe.c +0
-0for (i =0 ; i < n_cmds; i++) app->cmds[app->n_cmds + i]->data = app;examples/ip_pipeline/pipeline/pipeline_flow_classification.c +0
-0
examples/ip_pipeline/pipeline/pipeline_flow_classification.c app_pipeline_fc_key_convert(struct pipeline_fc_key · line 130
Quoted 5 lines
examples/ip_pipeline/pipeline/pipeline_flow_classification.c +0
-1@@ -126,7 +126,6 @@ app_pipeline_fc_key_convert(struct pipeline_fc_key *key_in, {struct pkt_key_ipv6_5tuple *ipv6 = key_buffer; -memset (ipv6,0 ,64 );
Agreed!
Quoted 5 lines
examples/ip_pipeline/pipeline/pipeline_flow_classification.c +0
-0ipv6->payload_length =0 ; ipv6->proto = key_in->key.ipv6_5tuple.proto;
ipv6->hop_limit= 0;
--
2.1.4
Re: [PATCH 3/5] example_ip_pipeline: fix sizeof() on memcpy
Quoted 14 lines · Cristian
examples/ip_pipeline/init.c app_pipeline_type_cmd_push(struct app_params · line 1329
Quoted 11 lines
examples/ip_pipeline/init.c +1
-1@@ -1325,7 +1325,7 @@ app_pipeline_type_cmd_push(struct app_params *app,/* Push pipeline commands into the application */ memcpy (&app->cmds[app->n_cmds], cmds, - n_cmds *sizeof (cmdline_parse_ctx_t *)); + n_cmds *sizeof (cmdline_parse_ctx_t));Actually no, as we are both the destination and the source of memcpy are array of pointers.
Quoted 1 line
The source is a pipeline type, which is a static global data structure, so no issues with the life time of the data pointed to by the pointers.
In order to make tools happy, shouldn't the source and target be pointers to array of pointers. In the current code
&app->cmd[app->n_cmds] is type cmdline_parse_ctx_t *
cmds is type cmdline_parse_ctx_t *
And type cmdline_parse_ctx_t is already a pointer.
Copying a set of pointers to pointers vs set of pointers will be the same since both are the same size, but static checking tools see the problem.
This is why kernel developers particularly despise typedefs which hide pointers like this one.
PATCH 4/5 examples_ip_pipeline: remove useless code
In reply to Stephen HemmingerCode here checks return from strdup() in only one place in this whole module, and then does nothing useful by setting one value that is then cleared. Just remove the check.
--- examples/ip_pipeline/config_parse.c | 3 --- 1 file changed, 3 deletions(-)
examples/ip_pipeline/config_parse.c +0 -3
@@ -1483,9 +1483,6 @@ parse_tm(struct app_params *app, ret = -ESRCH ;if (strcmp (ent->name,"cfg" ) ==0 ) { param->file_name =strdup (ent->value); -if (param->file_name ==NULL ) - ret = -EINVAL ; - ret =0 ; }else if (strcmp (ent->name,"burst_read" ) ==0 ) ret = parser_read_uint32(¶m->burst_read,
Signature · 1 line
2.1.4
Re: [PATCH 4/5] examples_ip_pipeline: remove useless code
Quoted 24 lines
-----Original Message-----
From: Stephen Hemminger [mailto:[email protected]]
Sent: Tuesday, September 1, 2015 4:59 AM
To: Dumitrescu, Cristian
Cc: [email protected]; Stephen Hemminger
Subject: [PATCH 4/5]examples_ip_pipeline: remove useless codeCode here checks return from
strdup()in only one place in this whole module, and then does nothing useful by setting one value that is then cleared. Just remove the check.Signed-off-by Stephen Hemminger <[email protected]>--- examples/ip_pipeline/config_parse.c | 3 --- 1 file changed, 3 deletions(-)examples/ip_pipeline/config_parse.c +0
-0
examples/ip_pipeline/config_parse.c parse_tm(struct app_params *app, · line 1486
Quoted 7 lines
examples/ip_pipeline/config_parse.c +0
-3@@ -1483,9 +1483,6 @@ parse_tm(struct app_params *app, ret = -ESRCH ;if (strcmp (ent->name,"cfg" ) ==0 ) { param->file_name =strdup (ent->value); -if (param->file_name ==NULL ) - ret = -EINVAL ; - ret =0 ;
The required implementation would actually be:
if (param->file_name == NULL) ret = -EINVAL; else ret = 0;
The TM parameter file_name is used by function app_config_parse_tm() in file config_parse_tm.c.
Regarding the way the error management (including the error messages) is done in our parser (currently done by repeatedly setting the ret variable), I would like to improve (replace) when I get the time to take another look at this.
Quoted 4 lines
examples/ip_pipeline/config_parse.c +0
-1}else if (strcmp (ent->name,"burst_read" ) ==0 ) ret = parser_read_uint32(¶m->burst_read, --2.1.4
PATCH 5/5 examples_ip_pipeline: fix possible string overrun
In reply to Stephen HemmingerIf a long name was passed the code would clobber memory with strcpy.
--- examples/ip_pipeline/app.h | 2 +- examples/ip_pipeline/init.c | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-)
examples/ip_pipeline/app.h +1 -1
@@ -190,7 +190,7 @@ struct app_pktq_out_params {#define APP_MAX_PIPELINE_ARGS PIPELINE_MAX_ARGSstruct app_pipeline_params { -char *name; +const char *name;uint8_t parsed;char type[APP_PIPELINE_TYPE_SIZE ];
examples/ip_pipeline/init.c +3 -2
@@ -1022,12 +1022,13 @@ app_init_msgq(struct app_params *app) }static void app_pipeline_params_get (struct app_params *app, -struct app_pipeline_params *p_in, +const struct app_pipeline_params *p_in,struct pipeline_params *p_out) {uint32_t i; -strcpy (p_out->name, p_in->name); +strncpy (p_out->name, p_in->name,PIPELINE_NAME_SIZE -1 ); + p_out->name[PIPELINE_NAME_SIZE -1 ] ='\0' ; p_out->socket_id = (int ) p_in->socket_id;
Signature · 1 line
2.1.4
Re: [PATCH 5/5] examples_ip_pipeline: fix possible string overrun
Quoted 38 lines
-----Original Message-----
From: Stephen Hemminger [mailto:[email protected]]
Sent: Tuesday, September 1, 2015 4:59 AM
To: Dumitrescu, Cristian
Cc: [email protected]; Stephen Hemminger
Subject: [PATCH 5/5]examples_ip_pipeline: fix possible string overrunIf a long name was passed the code would clobber memory with strcpy.
Signed-off-by Stephen Hemminger <[email protected]>--- examples/ip_pipeline/app.h | 2 +- examples/ip_pipeline/init.c | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-)examples/ip_pipeline/app.h +1
-1@@ -190,7 +190,7 @@ struct app_pktq_out_params {#define APP_MAX_PIPELINE_ARGS PIPELINE_MAX_ARGSstruct app_pipeline_params { -char *name; +const char *name;uint8_t parsed;char type[APP_PIPELINE_TYPE_SIZE ];examples/ip_pipeline/init.c +0
-0@@ -1022,12 +1022,13 @@ app_init_msgq(struct app_params *app) }
examples/ip_pipeline/init.c app_init_msgq(struct app_params *app) · line 1031
Quoted 10 lines
examples/ip_pipeline/init.c +3
-2static void app_pipeline_params_get (struct app_params *app, -struct app_pipeline_params *p_in, +const struct app_pipeline_params *p_in,struct pipeline_params *p_out) {uint32_t i; -strcpy (p_out->name, p_in->name); +strncpy (p_out->name, p_in->name,PIPELINE_NAME_SIZE -1 ); + p_out->name[PIPELINE_NAME_SIZE -1 ] ='\0' ;
Could be done, but not necessary, as the pipeline name string was already validated in the parser module; now it is just copied over, and it is safe to assume it of right size.
I don't mind doing it for extra safety.
Quoted 5 lines
examples/ip_pipeline/init.c +0
-1p_out->socket_id = (int ) p_in->socket_id; --2.1.4
Quoted 9 lines
-----Original Message-----
From: Stephen Hemminger [mailto:[email protected]]
Sent: Tuesday, September 1, 2015 4:59 AM
To: Dumitrescu, Cristian
Cc: [email protected]; Stephen Hemminger
Subject: [PATCH 0/5] fixup ip pipeline examples
Quoted 3 lines
Lots of little trivial bugs/typos here.
Let's not start users off with a bad example.
Thanks very much for doing this work, Steve!
I agree with most of the bug fixes here except a few, which I indicated in my reply to each individual patch.
Do you want to resend or do you want us to integrate the fixes in our next patches? Whatever works best for you is fine with us.
Regards,
Cristian
Hi,
2015-09-09 18:35, Dumitrescu, Cristian:
Quoted 9 lines
From: Stephen Hemminger [mailto:[email protected]]
Quoted 2 lines
Lots of little trivial bugs/typos here.
Let's not start users off with a bad example.Thanks very much for doing this work, Steve!
I agree with most of the bug fixes here except a few, which I indicated in my reply to each individual patch.
Do you want to resend or do you want us to integrate the fixes in our next patches? Whatever works best for you is fine with us.
Please, what are the news about this series?
In case it's already merged in another series, please advertise it. Thanks
Quoted 19 lines
-----Original Message-----
From: Thomas Monjalon [mailto:[email protected]]
Sent: Wednesday, October 7, 2015 5:43 PM
To: Dumitrescu, Cristian; Stephen Hemminger
Cc: [email protected]
Subject: Re: [dpdk-dev] [PATCH 0/5] fixup ip pipeline examplesHi,
2015-09-09 18:35, Dumitrescu, Cristian:
Quoted 7 lines
From: Stephen Hemminger [mailto:[email protected]]
Quoted 2 lines
Lots of little trivial bugs/typos here.
Let's not start users off with a bad example.Thanks very much for doing this work, Steve!
I agree with most of the bug fixes here except a few, which I indicated in
Quoted 8 lines
my reply to each individual patch.
Quoted 2 lines
Do you want to resend or do you want us to integrate the fixes in our next
patches? Whatever works best for you is fine with us.
Please, what are the news about this series?
In case it's already merged in another series, please advertise it. Thanks
Stephen, are you planning to send a new revision of this series? Thanks, Cristian