[PATCH linux-next] perf daemon: use strscpy() is more robust and safer
From: cgel . zte
Date: Wed Sep 21 2022 - 05:34:39 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/builtin-daemon.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/tools/perf/builtin-daemon.c b/tools/perf/builtin-daemon.c
index 6cb3f6cc36d0..1e927c4dcc81 100644
--- a/tools/perf/builtin-daemon.c
+++ b/tools/perf/builtin-daemon.c
@@ -606,7 +606,7 @@ static int setup_server_socket(struct daemon *daemon)
memset(&addr, 0, sizeof(addr));
addr.sun_family = AF_UNIX;
- strlcpy(addr.sun_path, path, sizeof(addr.sun_path) - 1);
+ strscpy(addr.sun_path, path, sizeof(addr.sun_path) - 1);
unlink(path);
if (bind(fd, (struct sockaddr *)&addr, sizeof(addr)) == -1) {
@@ -877,7 +877,7 @@ static int setup_client_socket(struct daemon *daemon)
memset(&addr, 0, sizeof(addr));
addr.sun_family = AF_UNIX;
- strlcpy(addr.sun_path, path, sizeof(addr.sun_path) - 1);
+ strscpy(addr.sun_path, path, sizeof(addr.sun_path) - 1);
if (connect(fd, (struct sockaddr *) &addr, sizeof(addr)) == -1) {
perror("failed: connect");
--
2.25.1