[master] ce91292 Always use bprintf() write to sockaddr_un.sun_path.

Geoff Simmons geoff at uplex.de
Fri Mar 23 12:45:16 UTC 2018


commit ce91292da0a95cd874b97ba6af97564b99bb92f8
Author: Geoff Simmons <geoff at uplex.de>
Date:   Fri Mar 23 13:42:21 2018 +0100

    Always use bprintf() write to sockaddr_un.sun_path.
    
    We already check the -a user input and emit an error if the path is
    too long.
    
    bprintf() should help persuade static analysis tools that we won't
    overflow the fixed-size buffer.

diff --git a/bin/varnishd/mgt/mgt_acceptor.c b/bin/varnishd/mgt/mgt_acceptor.c
index 796a11b..8ef0f3a 100644
--- a/bin/varnishd/mgt/mgt_acceptor.c
+++ b/bin/varnishd/mgt/mgt_acceptor.c
@@ -90,7 +90,7 @@ mac_opensocket(struct listen_sock *ls)
 		ls->sock = VTCP_bind(ls->addr, NULL);
 	else {
 		uds.sun_family = PF_UNIX;
-		strcpy(uds.sun_path, ls->endpoint);
+		bprintf(uds.sun_path, "%s", ls->endpoint);
 		ls->sock = VUS_bind(&uds, NULL);
 	}
 	fail = errno;
diff --git a/lib/libvarnish/vus.c b/lib/libvarnish/vus.c
index 69a223d..6315d95 100644
--- a/lib/libvarnish/vus.c
+++ b/lib/libvarnish/vus.c
@@ -33,6 +33,7 @@
 #include <errno.h>
 #include <string.h>
 #include <poll.h>
+#include <stdio.h>
 
 #include "vdef.h"
 #include "vas.h"
@@ -55,7 +56,7 @@ VUS_resolver(const char *path, vus_resolved_f *func, void *priv,
 		*err = "Path too long for a Unix domain socket";
 		return(-1);
 	}
-	strcpy(uds.sun_path, path);
+	bprintf(uds.sun_path, "%s", path);
 	uds.sun_family = PF_UNIX;
 	if (func != NULL)
 		ret = func(priv, &uds);
@@ -108,10 +109,8 @@ VUS_connect(const char *path, int msec)
 
 	if (path == NULL)
 		return (-1);
-	/* Attempt the connect */
-	assert(strlen(path) + 1 <= sizeof(uds.sun_path));
 	uds.sun_family = PF_UNIX;
-	strcpy(uds.sun_path, path);
+	bprintf(uds.sun_path, "%s", path);
 	AN(sl);
 
 	s = socket(PF_UNIX, SOCK_STREAM, 0);


More information about the varnish-commit mailing list