linux-perf-users.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Arnaldo Carvalho de Melo <acme@kernel.org>
To: cgel.zte@gmail.com
Cc: mingo@redhat.com, mark.rutland@arm.com,
	alexander.shishkin@linux.intel.com, jolsa@kernel.org,
	namhyung@kernel.org, irogers@google.com, songliubraving@fb.com,
	adrian.hunter@intel.com, davemarchevsky@fb.com,
	wcohen@redhat.com, andres@anarazel.de,
	linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org,
	ye xingchen <ye.xingchen@zte.com.cn>,
	Zeal Robot <zealci@zte.com.cn>
Subject: Re: [PATCH linux-next] perf annotate: use strscpy() is more robust and safer
Date: Thu, 22 Sep 2022 20:19:02 +0100	[thread overview]
Message-ID: <Yyy1JgWCuQTMKFkY@kernel.org> (raw)
In-Reply-To: <20220922012431.232372-1-ye.xingchen@zte.com.cn>

Em Thu, Sep 22, 2022 at 01:24:31AM +0000, cgel.zte@gmail.com escreveu:
> From: ye xingchen <ye.xingchen@zte.com.cn>
> 
> The implementation of strscpy() is more robust and safer.

Where is strscpy() defined?

I see it defined in the kernel:

⬢[acme@toolbox perf]$ grep -w strscpy include/linux/string.h
ssize_t strscpy(char *, const char *, size_t);
/* Wraps calls to strscpy()/memset(), no arch specific code required */
⬢[acme@toolbox perf]$

But not in tools/

Have you actually build with these patches?

- Arnaldo
 
> That's now the recommended way to copy NUL terminated strings.
> 
> Reported-by: Zeal Robot <zealci@zte.com.cn>
> Signed-off-by: ye xingchen <ye.xingchen@zte.com.cn>
> ---
>  tools/perf/util/annotate.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/tools/perf/util/annotate.c b/tools/perf/util/annotate.c
> index 5bc63c9e0324..e2b038b14ff6 100644
> --- a/tools/perf/util/annotate.c
> +++ b/tools/perf/util/annotate.c
> @@ -1702,7 +1702,7 @@ static int dso__disassemble_filename(struct dso *dso, char *filename, size_t fil
>  			char *new_name = filename_with_chroot(dso->nsinfo->pid,
>  							      filename);
>  			if (new_name) {
> -				strlcpy(filename, new_name, filename_size);
> +				strscpy(filename, new_name, filename_size);
>  				free(new_name);
>  			}
>  		}
> @@ -2002,7 +2002,7 @@ static int symbol__disassemble(struct symbol *sym, struct annotate_args *args)
>  		kce.len = sym->end - sym->start;
>  		if (!kcore_extract__create(&kce)) {
>  			delete_extract = true;
> -			strlcpy(symfs_filename, kce.extract_filename,
> +			strscpy(symfs_filename, kce.extract_filename,
>  				sizeof(symfs_filename));
>  		}
>  	} else if (dso__needs_decompress(dso)) {
> -- 
> 2.25.1

-- 

- Arnaldo

      reply	other threads:[~2022-09-22 19:19 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-09-22  1:24 [PATCH linux-next] perf annotate: use strscpy() is more robust and safer cgel.zte
2022-09-22 19:19 ` Arnaldo Carvalho de Melo [this message]

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=Yyy1JgWCuQTMKFkY@kernel.org \
    --to=acme@kernel.org \
    --cc=adrian.hunter@intel.com \
    --cc=alexander.shishkin@linux.intel.com \
    --cc=andres@anarazel.de \
    --cc=cgel.zte@gmail.com \
    --cc=davemarchevsky@fb.com \
    --cc=irogers@google.com \
    --cc=jolsa@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-perf-users@vger.kernel.org \
    --cc=mark.rutland@arm.com \
    --cc=mingo@redhat.com \
    --cc=namhyung@kernel.org \
    --cc=songliubraving@fb.com \
    --cc=wcohen@redhat.com \
    --cc=ye.xingchen@zte.com.cn \
    --cc=zealci@zte.com.cn \
    /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).