From: Andi Kleen <ak@linux.intel.com>
To: Rickard Strandqvist <rickard_strandqvist@spectrumdigital.se>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>,
Paul Mackerras <paulus@samba.org>, Ingo Molnar <mingo@redhat.com>,
Arnaldo Carvalho de Melo <acme@kernel.org>,
Jiri Olsa <jolsa@redhat.com>, Namhyung Kim <namhyung.kim@lge.com>,
Adrian Hunter <adrian.hunter@intel.com>,
Stephane Eranian <eranian@google.com>,
David Ahern <dsahern@gmail.com>,
Vince Weaver <vincent.weaver@maine.edu>,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH] tools: perf: util: parse-events.c: Cleaning up missing null-terminate after strncpy call
Date: Wed, 4 Jun 2014 15:20:47 -0700 [thread overview]
Message-ID: <20140604222047.GA16855@tassilo.jf.intel.com> (raw)
In-Reply-To: <1401918378-3842-1-git-send-email-rickard_strandqvist@spectrumdigital.se>
On Wed, Jun 04, 2014 at 11:46:18PM +0200, Rickard Strandqvist wrote:
> Added a guaranteed null-terminate after call to strncpy.
>
> This was partly found using a static code analysis program called cppcheck.
Should just stop using strncpy. strncpy semantics don't make any
sense at all, and it's inefficient. I would just snprintf here
-Andi
>
> Signed-off-by: Rickard Strandqvist <rickard_strandqvist@spectrumdigital.se>
> ---
> tools/perf/util/parse-events.c | 4 +++-
> 1 file changed, 3 insertions(+), 1 deletion(-)
>
> diff --git a/tools/perf/util/parse-events.c b/tools/perf/util/parse-events.c
> index 1e15df1..fad2976 100644
> --- a/tools/perf/util/parse-events.c
> +++ b/tools/perf/util/parse-events.c
> @@ -1216,8 +1216,10 @@ static void print_symbol_events(const char *event_glob, unsigned type,
>
> if (strlen(syms->alias))
> snprintf(name, MAX_NAME_LEN, "%s OR %s", syms->symbol, syms->alias);
> - else
> + else {
> strncpy(name, syms->symbol, MAX_NAME_LEN);
> + name[sizeof(name) - 1] = '\0';
> + }
>
> printf(" %-50s [%s]\n", name, event_type_descriptors[type]);
>
> --
> 1.7.10.4
>
--
ak@linux.intel.com -- Speaking for myself only
next prev parent reply other threads:[~2014-06-04 22:21 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-06-04 21:46 Rickard Strandqvist
2014-06-04 22:20 ` Andi Kleen [this message]
2014-06-04 22:23 ` Rickard Strandqvist
2014-06-04 22:31 ` Andi Kleen
2014-06-06 13:16 ` Rickard Strandqvist
2014-06-06 13:22 ` Jiri Olsa
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=20140604222047.GA16855@tassilo.jf.intel.com \
--to=ak@linux.intel.com \
--cc=a.p.zijlstra@chello.nl \
--cc=acme@kernel.org \
--cc=adrian.hunter@intel.com \
--cc=dsahern@gmail.com \
--cc=eranian@google.com \
--cc=jolsa@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=namhyung.kim@lge.com \
--cc=paulus@samba.org \
--cc=rickard_strandqvist@spectrumdigital.se \
--cc=vincent.weaver@maine.edu \
/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
Powered by JetHome