[dpdk-dev] examples/ip_pipeline: fix buffer not null terminated
Checks
Commit Message
The destination string may not have a null termination if
the source string's length is equal to the sizeof(pipeline->name).
Fix by replacing strncpy with strlcpy that guarantees NULL-termination.
Coverty issue: 272606
Fixes: d75c371e9b46 ("examples/ip_pipeline: add pipeline object")
Signed-off-by: Jasvinder Singh <jasvinder.singh@intel.com>
---
examples/ip_pipeline/pipeline.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
Comments
On Tue, Apr 17, 2018 at 02:28:25PM +0100, Jasvinder Singh wrote:
> The destination string may not have a null termination if
> the source string's length is equal to the sizeof(pipeline->name).
>
> Fix by replacing strncpy with strlcpy that guarantees NULL-termination.
>
> Coverty issue: 272606
> Fixes: d75c371e9b46 ("examples/ip_pipeline: add pipeline object")
>
> Signed-off-by: Jasvinder Singh <jasvinder.singh@intel.com>
Does this need an include of rte_string_fns.h?
In terms of the change itself:
Acked-by: Bruce Richardson <bruce.richardson@intel.com>
> ---
> examples/ip_pipeline/pipeline.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/examples/ip_pipeline/pipeline.c b/examples/ip_pipeline/pipeline.c
> index 76aa1d3..132f1a8 100644
> --- a/examples/ip_pipeline/pipeline.c
> +++ b/examples/ip_pipeline/pipeline.c
> @@ -129,7 +129,7 @@ pipeline_create(const char *name, struct pipeline_params *params)
> }
>
> /* Node fill in */
> - strncpy(pipeline->name, name, sizeof(pipeline->name));
> + strlcpy(pipeline->name, name, sizeof(pipeline->name));
> pipeline->p = p;
> pipeline->n_ports_in = 0;
> pipeline->n_ports_out = 0;
> --
> 2.9.3
>
> -----Original Message-----
> From: Richardson, Bruce
> Sent: Tuesday, April 17, 2018 4:01 PM
> To: Singh, Jasvinder <jasvinder.singh@intel.com>
> Cc: dev@dpdk.org; Dumitrescu, Cristian <cristian.dumitrescu@intel.com>
> Subject: Re: [dpdk-dev] [PATCH] examples/ip_pipeline: fix buffer not null
> terminated
>
> On Tue, Apr 17, 2018 at 02:28:25PM +0100, Jasvinder Singh wrote:
> > The destination string may not have a null termination if the source
> > string's length is equal to the sizeof(pipeline->name).
> >
> > Fix by replacing strncpy with strlcpy that guarantees NULL-termination.
> >
> > Coverty issue: 272606
> > Fixes: d75c371e9b46 ("examples/ip_pipeline: add pipeline object")
> >
> > Signed-off-by: Jasvinder Singh <jasvinder.singh@intel.com>
>
> Does this need an include of rte_string_fns.h?
>
> In terms of the change itself:
>
> Acked-by: Bruce Richardson <bruce.richardson@intel.com>
>
It got reference of rte_string_fns.h through other header files there. So build was ok, but I will send v2 with explicit include. Thanks.
@@ -129,7 +129,7 @@ pipeline_create(const char *name, struct pipeline_params *params)
}
/* Node fill in */
- strncpy(pipeline->name, name, sizeof(pipeline->name));
+ strlcpy(pipeline->name, name, sizeof(pipeline->name));
pipeline->p = p;
pipeline->n_ports_in = 0;
pipeline->n_ports_out = 0;