DPDK patches and discussions
 help / color / mirror / Atom feed
From: Bruce Richardson <bruce.richardson@intel.com>
To: Stephen Hemminger <stephen@networkplumber.org>
Cc: dev@dpdk.org
Subject: Re: [dpdk-dev] [PATCH 2/5] example_ip_pipeline: avoid strncpy issue
Date: Thu, 10 Sep 2015 09:44:03 +0100	[thread overview]
Message-ID: <20150910084403.GA25956@bricha3-MOBL3> (raw)
In-Reply-To: <1441072746-29174-3-git-send-email-stephen@networkplumber.org>

On Mon, Aug 31, 2015 at 06:59:03PM -0700, Stephen Hemminger wrote:
> If name is so long that it fills buffer, then string would not
> be null terminated.
> 
> Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
> ---
>  examples/ip_pipeline/config_parse_tm.c | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
> 
> diff --git a/examples/ip_pipeline/config_parse_tm.c b/examples/ip_pipeline/config_parse_tm.c
> index 84702b0..4a35715 100644
> --- a/examples/ip_pipeline/config_parse_tm.c
> +++ b/examples/ip_pipeline/config_parse_tm.c
> @@ -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),
> -- 
> 2.1.4
> 
Would using snprintf rather than strncpy be tidier? Would save having to worry
about null termination at all.

/Bruce

  parent reply	other threads:[~2015-09-10  8:44 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-09-01  1:59 [dpdk-dev] [PATCH 0/5] fixup ip pipeline examples Stephen Hemminger
2015-09-01  1:59 ` [dpdk-dev] [PATCH 1/5] examples_ip_pipeline: fix typo's Stephen Hemminger
2015-09-09 18:21   ` Dumitrescu, Cristian
2015-09-01  1:59 ` [dpdk-dev] [PATCH 2/5] example_ip_pipeline: avoid strncpy issue Stephen Hemminger
2015-09-09 18:22   ` Dumitrescu, Cristian
2015-09-10  8:44   ` Bruce Richardson [this message]
2015-09-01  1:59 ` [dpdk-dev] [PATCH 3/5] example_ip_pipeline: fix sizeof() on memcpy Stephen Hemminger
2015-09-09 18:25   ` Dumitrescu, Cristian
2015-09-09 18:47     ` Stephen Hemminger
2015-09-01  1:59 ` [dpdk-dev] [PATCH 4/5] examples_ip_pipeline: remove useless code Stephen Hemminger
2015-09-09 18:31   ` Dumitrescu, Cristian
2015-09-01  1:59 ` [dpdk-dev] [PATCH 5/5] examples_ip_pipeline: fix possible string overrun Stephen Hemminger
2015-09-09 18:33   ` Dumitrescu, Cristian
2015-09-09 18:35 ` [dpdk-dev] [PATCH 0/5] fixup ip pipeline examples Dumitrescu, Cristian
2015-10-07 16:43   ` Thomas Monjalon
2015-10-12 14:51     ` Dumitrescu, Cristian

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20150910084403.GA25956@bricha3-MOBL3 \
    --to=bruce.richardson@intel.com \
    --cc=dev@dpdk.org \
    --cc=stephen@networkplumber.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).