[PATCH linux-next] perf llvm: use strscpy() is more robust and safer

From: cgel . zte
Date: Wed Sep 21 2022 - 21:31:55 EST


From: ye xingchen <ye.xingchen@xxxxxxxxxx>

The implementation of strscpy() is more robust and safer.

That's now the recommended way to copy NUL terminated strings.

Reported-by: Zeal Robot <zealci@xxxxxxxxxx>
Signed-off-by: ye xingchen <ye.xingchen@xxxxxxxxxx>
---
tools/perf/util/llvm-utils.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/tools/perf/util/llvm-utils.c b/tools/perf/util/llvm-utils.c
index 2dc797007419..3e218cb8f0ae 100644
--- a/tools/perf/util/llvm-utils.c
+++ b/tools/perf/util/llvm-utils.c
@@ -80,7 +80,7 @@ search_program(const char *def, const char *name,
if (def && def[0] != '\0') {
if (def[0] == '/') {
if (access(def, F_OK) == 0) {
- strlcpy(output, def, PATH_MAX);
+ strscpy(output, def, PATH_MAX);
return 0;
}
} else if (def[0] != '\0')
@@ -99,7 +99,7 @@ search_program(const char *def, const char *name,
while (path) {
scnprintf(buf, sizeof(buf), "%s/%s", path, name);
if (access(buf, F_OK) == 0) {
- strlcpy(output, buf, PATH_MAX);
+ strscpy(output, buf, PATH_MAX);
ret = 0;
break;
}
--
2.25.1