DPDK patches and discussions
 help / color / mirror / Atom feed
From: Stephen Hemminger <stephen@networkplumber.org>
To: Pallantla Poornima <pallantlax.poornima@intel.com>
Cc: dev@dpdk.org, reshma.pattan@intel.com, ferruh.yigit@intel.com,
	stable@dpdk.org
Subject: Re: [dpdk-dev] [PATCH] test: fix sprintf with snprintf
Date: Fri, 8 Feb 2019 08:21:39 -0800	[thread overview]
Message-ID: <20190208082139.57e8e060@hermes.lan> (raw)
In-Reply-To: <1549632457-15892-1-git-send-email-pallantlax.poornima@intel.com>

On Fri,  8 Feb 2019 13:27:37 +0000
Pallantla Poornima <pallantlax.poornima@intel.com> wrote:

> diff --git a/test/test/commands.c b/test/test/commands.c
> index 94fbc310e..5aeb35498 100644
> --- a/test/test/commands.c
> +++ b/test/test/commands.c
> @@ -367,6 +367,8 @@ int commands_init(void)
>  	struct test_command *t;
>  	char *commands, *ptr;
>  	int commands_len = 0;
> +	int total_written = 0;
> +	int count = 0;
>  
>  	TAILQ_FOREACH(t, &commands_list, next) {
>  		commands_len += strlen(t->command) + 1;
> @@ -378,7 +380,10 @@ int commands_init(void)
>  
>  	ptr = commands;
>  	TAILQ_FOREACH(t, &commands_list, next) {
> -		ptr += sprintf(ptr, "%s#", t->command);
> +		count = snprintf(ptr, commands_len - total_written - 1, "%s#",
> +				t->command);
> +		ptr += count;
> +		total_written += count;

You know snprintf is dangerous in this case as well.
It returns the number of bytes that would have been written.

That is why the linux kernel introduced scnprintf.

  parent reply	other threads:[~2019-02-08 16:21 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-02-08 13:27 Pallantla Poornima
2019-02-08 14:04 ` Bruce Richardson
2019-02-08 16:21 ` Stephen Hemminger [this message]
2019-02-08 17:04 ` Aaron Conole
2019-02-08 17:35   ` Stephen Hemminger

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=20190208082139.57e8e060@hermes.lan \
    --to=stephen@networkplumber.org \
    --cc=dev@dpdk.org \
    --cc=ferruh.yigit@intel.com \
    --cc=pallantlax.poornima@intel.com \
    --cc=reshma.pattan@intel.com \
    --cc=stable@dpdk.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).