monitor: Fix truncated server socket path parameter
authorMariusz Skamra <mariusz.skamra@codecoup.pl>
Wed, 4 Aug 2021 10:54:46 +0000 (12:54 +0200)
committerAyush Garg <ayush.garg@samsung.com>
Fri, 11 Mar 2022 13:38:36 +0000 (19:08 +0530)
This fixes the issue of --server <socket> parameter
last character was dropped. There is no need to use
strncpy, as the length is already checked, and it is
known that the destination buffer is big enough

Signed-off-by: Anuj Jain <anuj01.jain@samsung.com>
Signed-off-by: Ayush Garg <ayush.garg@samsung.com>
monitor/control.c

index cc9385f..025d461 100755 (executable)
@@ -1164,14 +1164,12 @@ static int server_fd = -1;
 void control_server(const char *path)
 {
        struct sockaddr_un addr;
-       size_t len;
        int fd;
 
        if (server_fd >= 0)
                return;
 
-       len = strlen(path);
-       if (len > sizeof(addr.sun_path) - 1) {
+       if (strlen(path) > sizeof(addr.sun_path) - 1) {
                fprintf(stderr, "Socket name too long\n");
                return;
        }
@@ -1186,7 +1184,7 @@ void control_server(const char *path)
 
        memset(&addr, 0, sizeof(addr));
        addr.sun_family = AF_UNIX;
-       strncpy(addr.sun_path, path, len - 1);
+       strcpy(addr.sun_path, path);
 
        if (bind(fd, (struct sockaddr *) &addr, sizeof(addr)) < 0) {
                perror("Failed to bind server socket");