X-Git-Url: https://tinc-vpn.org/git/browse?a=blobdiff_plain;f=src%2Fcontrol.c;h=175f2bd019f66771350086e560eb0f7d1e26713d;hb=04d8a8e34e1fe7f33f1946863b36a24ee358175f;hp=beda6c41c0e27b2008a7c6e36caca7eb4486011e;hpb=a6448291834ca7419553a807ee367c719c2956d0;p=tinc diff --git a/src/control.c b/src/control.c index beda6c41..175f2bd0 100644 --- a/src/control.c +++ b/src/control.c @@ -22,9 +22,7 @@ #include "conf.h" #include "control.h" #include "control_common.h" -#include "graph.h" #include "logger.h" -#include "meta.h" #include "names.h" #include "net.h" #include "netutl.h" @@ -110,7 +108,7 @@ bool control_h(connection_t *c, const char *request) { return control_return(c, REQ_DISCONNECT, -1); } - for list_each(connection_t, other, connection_list) { + for list_each(connection_t, other, &connection_list) { if(strcmp(other->name, name)) { continue; } @@ -159,12 +157,12 @@ bool init_control(void) { // Get the address and port of the first listening socket char *localhost = NULL; - sockaddr_t sa; + sockaddr_t sa = {0}; socklen_t len = sizeof(sa); // Make sure we have a valid address, and map 0.0.0.0 and :: to 127.0.0.1 and ::1. - if(getsockname(listen_socket[0].tcp.fd, (struct sockaddr *)&sa, &len)) { + if(getsockname(listen_socket[0].tcp.fd, &sa.sa, &len)) { xasprintf(&localhost, "127.0.0.1 port %s", myport); } else { if(sa.sa.sa_family == AF_INET) { @@ -195,14 +193,17 @@ bool init_control(void) { return false; } - struct sockaddr_un sa_un; + struct sockaddr_un sa_un = { + .sun_family = AF_UNIX, + }; - sa_un.sun_family = AF_UNIX; + if(strlen(unixsocketname) >= sizeof(sa_un.sun_path)) { + logger(DEBUG_ALWAYS, LOG_ERR, "UNIX socket filename %s is too long!", unixsocketname); + return false; + } strncpy(sa_un.sun_path, unixsocketname, sizeof(sa_un.sun_path)); - sa_un.sun_path[sizeof(sa_un.sun_path) - 1] = 0; - if(connect(unix_fd, (struct sockaddr *)&sa_un, sizeof(sa_un)) >= 0) { logger(DEBUG_ALWAYS, LOG_ERR, "UNIX socket %s is still in use!", unixsocketname); return false;