[PATCH linux-next] perf intel-pt: replace strlcpy() with strscpy()

From: yang.guang5
Date: Mon Dec 11 2023 - 22:23:20 EST


From: Yang Guang <yang.guang5@xxxxxxxxxx>

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@xxxxxxxxxx>
---
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