Check that UNIX socket filenames are not too long.
[tinc] / src / tincctl.c
index bfc16af..8b49c44 100644 (file)
@@ -853,14 +853,17 @@ bool connect_tincd(bool verbose) {
                return false;
        }
 
-       struct sockaddr_un sa;
+       struct sockaddr_un sa = {
+               .sun_family = AF_UNIX,
+       };
 
-       sa.sun_family = AF_UNIX;
+       if(strlen(unixsocketname) >= sizeof(sa.sun_path)) {
+               fprintf(stderr, "UNIX socket filename %s is too long!", unixsocketname);
+               return false;
+       }
 
        strncpy(sa.sun_path, unixsocketname, sizeof(sa.sun_path));
 
-       sa.sun_path[sizeof(sa.sun_path) - 1] = 0;
-
        fd = socket(AF_UNIX, SOCK_STREAM, 0);
 
        if(fd < 0) {