The Linux Kernel Mailing List
 help / color / mirror / Atom feed
From: Adrian Hunter <adrian.hunter@intel.com>
To: yang.guang5@zte.com.cn
Cc: jiang.xuexin@zte.com.cn, chen.haonan2@zte.com.cn,
	cgel.zte@gmail.com, mingo@redhat.com, acme@kernel.org,
	mark.rutland@arm.com, alexander.shishkin@linux.intel.com,
	jolsa@kernel.org, namhyung@kernel.org, irogers@google.com,
	liam.howlett@oracle.com, ojeda@kernel.org,
	linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org,
	peterz@infradead.org
Subject: Re: [PATCH linux-next] perf intel-pt: replace strlcpy() with strscpy()
Date: Tue, 12 Dec 2023 18:29:46 +0200	[thread overview]
Message-ID: <6b6a238d-4b1c-452f-8061-6840d44120bc@intel.com> (raw)
In-Reply-To: <202312121122562881958@zte.com.cn>

On 12/12/23 05:22, yang.guang5@zte.com.cn wrote:
> From: Yang Guang <yang.guang5@zte.com.cn>
> 
> strlcpy() reads the entire source buffer first. This read may exceed
> the destination size limit. This is both inefficient and can lead
> to linear read overflows if a source string is not NUL-terminated.
> No return values were used, so direct replacement is safe.
> 
> Signed-off-by: Chen Haonan <chen.haonan2@zte.com.cn>
> ---
>  tools/perf/util/intel-pt-decoder/intel-pt-decoder.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/tools/perf/util/intel-pt-decoder/intel-pt-decoder.c b/tools/perf/util/intel-pt-decoder/intel-pt-decoder.c
> index b450178e3420..5b14c6701ecb 100644
> --- a/tools/perf/util/intel-pt-decoder/intel-pt-decoder.c
> +++ b/tools/perf/util/intel-pt-decoder/intel-pt-decoder.c
> @@ -507,7 +507,7 @@ int intel_pt__strerror(int code, char *buf, size_t buflen)
>  {
>  	if (code < 1 || code >= INTEL_PT_ERR_MAX)
>  		code = INTEL_PT_ERR_UNK;
> -	strlcpy(buf, intel_pt_err_msgs[code], buflen);
> +	strscpy(buf, intel_pt_err_msgs[code], buflen);
>  	return 0;
>  }
> 

perf doesn't have strscpy():

util/intel-pt-decoder/intel-pt-decoder.c: In function ‘intel_pt__strerror’:
util/intel-pt-decoder/intel-pt-decoder.c:510:9: error: implicit declaration of function ‘strscpy’; did you mean ‘strlcpy’? [-Werror=implicit-function-declaration]
  510 |         strscpy(buf, intel_pt_err_msgs[code], buflen);
      |         ^~~~~~~
      |         strlcpy
cc1: all warnings being treated as errors


      reply	other threads:[~2023-12-12 16:30 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-12-12  3:22 [PATCH linux-next] perf intel-pt: replace strlcpy() with strscpy() yang.guang5
2023-12-12 16:29 ` Adrian Hunter [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=6b6a238d-4b1c-452f-8061-6840d44120bc@intel.com \
    --to=adrian.hunter@intel.com \
    --cc=acme@kernel.org \
    --cc=alexander.shishkin@linux.intel.com \
    --cc=cgel.zte@gmail.com \
    --cc=chen.haonan2@zte.com.cn \
    --cc=irogers@google.com \
    --cc=jiang.xuexin@zte.com.cn \
    --cc=jolsa@kernel.org \
    --cc=liam.howlett@oracle.com \
    --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=ojeda@kernel.org \
    --cc=peterz@infradead.org \
    --cc=yang.guang5@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