* [PATCH linux-next] perf intel-pt: replace strlcpy() with strscpy()
@ 2023-12-12 3:22 yang.guang5
2023-12-12 16:29 ` Adrian Hunter
0 siblings, 1 reply; 2+ messages in thread
From: yang.guang5 @ 2023-12-12 3:22 UTC (permalink / raw)
To: peterz
Cc: jiang.xuexin, chen.haonan2, cgel.zte, mingo, acme, mark.rutland,
alexander.shishkin, jolsa, namhyung, irogers, adrian.hunter,
liam.howlett, ojeda, linux-perf-users, linux-kernel
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;
}
--
2.25.1
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH linux-next] perf intel-pt: replace strlcpy() with strscpy()
2023-12-12 3:22 [PATCH linux-next] perf intel-pt: replace strlcpy() with strscpy() yang.guang5
@ 2023-12-12 16:29 ` Adrian Hunter
0 siblings, 0 replies; 2+ messages in thread
From: Adrian Hunter @ 2023-12-12 16:29 UTC (permalink / raw)
To: yang.guang5
Cc: jiang.xuexin, chen.haonan2, cgel.zte, mingo, acme, mark.rutland,
alexander.shishkin, jolsa, namhyung, irogers, liam.howlett, ojeda,
linux-perf-users, linux-kernel, peterz
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
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2023-12-12 16:29 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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 is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.