[dpdk-dev] [PATCH 5/5] examples_ip_pipeline: fix possible string overrun
Dumitrescu, Cristian
cristian.dumitrescu at intel.com
Wed Sep 9 20:33:09 CEST 2015
> -----Original Message-----
> From: Stephen Hemminger [mailto:stephen at networkplumber.org]
> Sent: Tuesday, September 1, 2015 4:59 AM
> To: Dumitrescu, Cristian
> Cc: dev at dpdk.org; Stephen Hemminger
> Subject: [PATCH 5/5] examples_ip_pipeline: fix possible string overrun
>
> If a long name was passed the code would clobber memory with
> strcpy.
>
> Signed-off-by: Stephen Hemminger <stephen at networkplumber.org>
> ---
> examples/ip_pipeline/app.h | 2 +-
> examples/ip_pipeline/init.c | 5 +++--
> 2 files changed, 4 insertions(+), 3 deletions(-)
>
> diff --git a/examples/ip_pipeline/app.h b/examples/ip_pipeline/app.h
> index 521e3a0..1f6bf0c 100644
> --- a/examples/ip_pipeline/app.h
> +++ b/examples/ip_pipeline/app.h
> @@ -190,7 +190,7 @@ struct app_pktq_out_params {
> #define APP_MAX_PIPELINE_ARGS PIPELINE_MAX_ARGS
>
> struct app_pipeline_params {
> - char *name;
> + const char *name;
> uint8_t parsed;
>
> char type[APP_PIPELINE_TYPE_SIZE];
> diff --git a/examples/ip_pipeline/init.c b/examples/ip_pipeline/init.c
> index 75e3767..007af83 100644
> --- a/examples/ip_pipeline/init.c
> +++ b/examples/ip_pipeline/init.c
> @@ -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';
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.
>
> p_out->socket_id = (int) p_in->socket_id;
>
> --
> 2.1.4
More information about the dev
mailing list