Thread (5 messages) flat view 5 messages, 3 authors, 2021-08-04

Re: [PATCH v2] monitor: Fix truncated server socket path parameter

From: Szymon Janc <hidden>
Date: 2021-08-04 14:53:46

Hello Mariusz,

On Wednesday, 4 August 2021 12:54:46 CEST Mariusz Skamra wrote:
quoted hunk ↗ jump to hunk
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
---
 monitor/control.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
diff --git a/monitor/control.c b/monitor/control.c
index d1ba97d37..266602a34 100644
--- a/monitor/control.c
+++ b/monitor/control.c
@@ -1165,14 +1165,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;
 	}
@@ -1187,7 +1185,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");
Patch applied, thanks.

-- 
pozdrawiam
Szymon Janc

Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help