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

From: cgel . zte
Date: Wed Sep 21 2022 - 05:32:54 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/symbol.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/tools/perf/util/symbol.c b/tools/perf/util/symbol.c
index a3a165ae933a..689007a23335 100644
--- a/tools/perf/util/symbol.c
+++ b/tools/perf/util/symbol.c
@@ -1886,7 +1886,7 @@ int dso__load(struct dso *dso, struct map *map)
name);
if (new_name) {
is_reg = is_regular_file(new_name);
- strlcpy(name, new_name, PATH_MAX);
+ strscpy(name, new_name, PATH_MAX);
free(new_name);
}
}
@@ -2138,7 +2138,7 @@ static int find_matching_kcore(struct map *map, char *dir, size_t dir_sz)
scnprintf(kallsyms_filename, sizeof(kallsyms_filename),
"%s/%s/kallsyms", dir, nd->s);
if (!validate_kcore_addresses(kallsyms_filename, map)) {
- strlcpy(dir, kallsyms_filename, dir_sz);
+ strscpy(dir, kallsyms_filename, dir_sz);
ret = 0;
break;
}
--
2.25.1