From: Guus Sliepen Date: Fri, 3 Nov 2017 23:20:32 +0000 (+0100) Subject: Fix all -Wall -W compiler warnings. X-Git-Tag: release-1.0.33~8 X-Git-Url: https://tinc-vpn.org/git/browse?a=commitdiff_plain;h=2116c6eb7d328c7aa3ce3da54f95367e5199d373;p=tinc Fix all -Wall -W compiler warnings. --- diff --git a/src/conf.c b/src/conf.c index 3289c587..c933f099 100644 --- a/src/conf.c +++ b/src/conf.c @@ -204,7 +204,7 @@ bool get_config_address(const config_t *cfg, struct addrinfo **result) { } bool get_config_subnet(const config_t *cfg, subnet_t **result) { - subnet_t subnet = {NULL}; + subnet_t subnet = {}; if(!cfg) { return false; diff --git a/src/connection.h b/src/connection.h index 1cc98186..30a645ad 100644 --- a/src/connection.h +++ b/src/connection.h @@ -32,16 +32,16 @@ #define OPTION_CLAMP_MSS 0x0008 typedef struct connection_status_t { - unsigned int pinged: 1; /* sent ping */ - unsigned int active: 1; /* 1 if active.. */ - unsigned int connecting: 1; /* 1 if we are waiting for a non-blocking connect() to finish */ - unsigned int unused_termreq: 1; /* the termination of this connection was requested */ - unsigned int remove: 1; /* Set to 1 if you want this connection removed */ - unsigned int timeout: 1; /* 1 if gotten timeout */ - unsigned int encryptout: 1; /* 1 if we can encrypt outgoing traffic */ - unsigned int decryptin: 1; /* 1 if we have to decrypt incoming traffic */ - unsigned int mst: 1; /* 1 if this connection is part of a minimum spanning tree */ - unsigned int proxy_passed: 1; /* 1 if we are connecting via a proxy and we have finished talking with it */ + unsigned int pinged: 1; /* sent ping */ + unsigned int active: 1; /* 1 if active.. */ + unsigned int connecting: 1; /* 1 if we are waiting for a non-blocking connect() to finish */ + unsigned int unused_termreq: 1; /* the termination of this connection was requested */ + unsigned int remove: 1; /* Set to 1 if you want this connection removed */ + unsigned int timeout: 1; /* 1 if gotten timeout */ + unsigned int encryptout: 1; /* 1 if we can encrypt outgoing traffic */ + unsigned int decryptin: 1; /* 1 if we have to decrypt incoming traffic */ + unsigned int mst: 1; /* 1 if this connection is part of a minimum spanning tree */ + unsigned int proxy_passed: 1; /* 1 if we are connecting via a proxy and we have finished talking with it */ unsigned int unused: 22; } connection_status_t; @@ -50,14 +50,14 @@ typedef struct connection_status_t { #include "node.h" typedef struct connection_t { - char *name; /* name he claims to have */ + char *name; /* name he claims to have */ - union sockaddr_t address; /* his real (internet) ip */ - char *hostname; /* the hostname of its real ip */ + union sockaddr_t address; /* his real (internet) ip */ + char *hostname; /* the hostname of its real ip */ int protocol_version; /* used protocol */ - int socket; /* socket used for this connection */ - uint32_t options; /* options for this connection */ + int socket; /* socket used for this connection */ + uint32_t options; /* options for this connection */ connection_status_t status; /* status info */ int estimated_weight; /* estimation for the weight of the edge for this connection */ struct timeval start; /* time this connection was started, used for above estimation */ @@ -66,36 +66,36 @@ typedef struct connection_t { struct node_t *node; /* node associated with the other end */ struct edge_t *edge; /* edge associated with this connection */ - RSA *rsa_key; /* his public/private key */ + RSA *rsa_key; /* his public/private key */ const EVP_CIPHER *incipher; /* Cipher he will use to send data to us */ const EVP_CIPHER *outcipher; /* Cipher we will use to send data to him */ EVP_CIPHER_CTX *inctx; /* Context of encrypted meta data that will come from him to us */ EVP_CIPHER_CTX *outctx; /* Context of encrypted meta data that will be sent from us to him */ uint64_t inbudget; /* Encrypted bytes send budget */ uint64_t outbudget; /* Encrypted bytes receive budget */ - char *inkey; /* His symmetric meta key + iv */ - char *outkey; /* Our symmetric meta key + iv */ - int inkeylength; /* Length of his key + iv */ - int outkeylength; /* Length of our key + iv */ + char *inkey; /* His symmetric meta key + iv */ + char *outkey; /* Our symmetric meta key + iv */ + int inkeylength; /* Length of his key + iv */ + int outkeylength; /* Length of our key + iv */ const EVP_MD *indigest; const EVP_MD *outdigest; int inmaclength; int outmaclength; int incompression; int outcompression; - char *mychallenge; /* challenge we received from him */ - char *hischallenge; /* challenge we sent to him */ + char *mychallenge; /* challenge we received from him */ + char *hischallenge; /* challenge we sent to him */ char buffer[MAXBUFSIZE]; /* metadata input buffer */ - int buflen; /* bytes read into buffer */ - int reqlen; /* length of incoming request */ - int tcplen; /* length of incoming TCPpacket */ - int allow_request; /* defined if there's only one request possible */ - - char *outbuf; /* metadata output buffer */ - int outbufstart; /* index of first meaningful byte in output buffer */ - int outbuflen; /* number of meaningful bytes in output buffer */ - int outbufsize; /* number of bytes allocated to output buffer */ + int buflen; /* bytes read into buffer */ + int reqlen; /* length of incoming request */ + length_t tcplen; /* length of incoming TCPpacket */ + int allow_request; /* defined if there's only one request possible */ + + char *outbuf; /* metadata output buffer */ + int outbufstart; /* index of first meaningful byte in output buffer */ + int outbuflen; /* number of meaningful bytes in output buffer */ + int outbufsize; /* number of bytes allocated to output buffer */ time_t last_ping_time; /* last time we saw some activity from the other end or pinged them */ time_t last_flushed_time; /* last time buffer was empty. Only meaningful if outbuflen > 0 */ diff --git a/src/dummy_device.c b/src/dummy_device.c index 9dd3fae7..deda7d46 100644 --- a/src/dummy_device.c +++ b/src/dummy_device.c @@ -39,6 +39,7 @@ static void close_device(void) { } static bool read_packet(vpn_packet_t *packet) { + (void)packet; return false; } diff --git a/src/meta.c b/src/meta.c index 49308184..ee55ecd7 100644 --- a/src/meta.c +++ b/src/meta.c @@ -59,7 +59,7 @@ bool send_meta(connection_t *c, const char *buffer, int length) { /* Add our data to buffer */ if(c->status.encryptout) { /* Check encryption limits */ - if(length > c->outbudget) { + if((uint64_t)length > c->outbudget) { ifdebug(META) logger(LOG_ERR, "Byte limit exceeded for encryption to %s (%s)", c->name, c->hostname); return false; } else { @@ -174,7 +174,7 @@ bool receive_meta(connection_t *c) { /* Is it proxy metadata? */ if(c->allow_request == PROXY) { - reqlen = receive_proxy_meta(c, oldlen, lenin); + reqlen = receive_proxy_meta(c); if(reqlen < 0) { return false; @@ -187,7 +187,7 @@ bool receive_meta(connection_t *c) { if(c->status.decryptin && !decrypted) { /* Check decryption limits */ - if(lenin > c->inbudget) { + if((uint64_t)lenin > c->inbudget) { ifdebug(META) logger(LOG_ERR, "Byte limit exceeded for decryption from %s (%s)", c->name, c->hostname); return false; } else { diff --git a/src/net.h b/src/net.h index c0e5b317..bb608902 100644 --- a/src/net.h +++ b/src/net.h @@ -48,7 +48,7 @@ typedef struct ipv6_t { uint16_t x[8]; } ipv6_t; -typedef short length_t; +typedef uint16_t length_t; #define AF_UNKNOWN 255 @@ -137,7 +137,7 @@ extern bool handle_new_meta_connection(int); extern int setup_listen_socket(const sockaddr_t *); extern int setup_vpn_in_socket(const sockaddr_t *); extern void send_packet(const struct node_t *, vpn_packet_t *); -extern void receive_tcppacket(struct connection_t *, const char *, int); +extern void receive_tcppacket(struct connection_t *, const char *, length_t); extern void broadcast_packet(const struct node_t *, vpn_packet_t *); extern char *get_name(void); extern bool setup_network(void); diff --git a/src/net_packet.c b/src/net_packet.c index 2a419cae..faf8378f 100644 --- a/src/net_packet.c +++ b/src/net_packet.c @@ -214,7 +214,7 @@ static length_t compress_packet(uint8_t *dest, const uint8_t *source, length_t l lzo1x_1_compress(source, len, dest, &lzolen, lzo_wrkmem); return lzolen; #else - return -1; + return 0; #endif } else if(level < 10) { #ifdef HAVE_ZLIB @@ -224,18 +224,18 @@ static length_t compress_packet(uint8_t *dest, const uint8_t *source, length_t l return destlen; } else #endif - return -1; + return 0; } else { #ifdef HAVE_LZO lzo_uint lzolen = MAXSIZE; lzo1x_999_compress(source, len, dest, &lzolen, lzo_wrkmem); return lzolen; #else - return -1; + return 0; #endif } - return -1; + return 0; } static length_t uncompress_packet(uint8_t *dest, const uint8_t *source, length_t len, int level) { @@ -250,7 +250,7 @@ static length_t uncompress_packet(uint8_t *dest, const uint8_t *source, length_t return lzolen; } else #endif - return -1; + return 0; } #ifdef HAVE_ZLIB @@ -260,7 +260,7 @@ static length_t uncompress_packet(uint8_t *dest, const uint8_t *source, length_t if(uncompress(dest, &destlen, source, len) == Z_OK) { return destlen; } else { - return -1; + return 0; } } @@ -297,7 +297,6 @@ static void receive_udppacket(node_t *n, vpn_packet_t *inpkt) { vpn_packet_t *outpkt; int outlen, outpad; unsigned char hmac[EVP_MAX_MD_SIZE]; - int i; if(!n->inkey) { ifdebug(TRAFFIC) logger(LOG_DEBUG, "Got packet from %s (%s) but he hasn't got our key yet", @@ -369,7 +368,7 @@ static void receive_udppacket(node_t *n, vpn_packet_t *inpkt) { return; } } else { - for(i = n->received_seqno + 1; i < inpkt->seqno; i++) { + for(uint32_t i = n->received_seqno + 1; i < inpkt->seqno; i++) { n->late[(i / 8) % replaywin] |= 1 << i % 8; } } @@ -394,7 +393,7 @@ static void receive_udppacket(node_t *n, vpn_packet_t *inpkt) { if(n->incompression) { outpkt = pkt[nextpkt++]; - if((outpkt->len = uncompress_packet(outpkt->data, inpkt->data, inpkt->len, n->incompression)) < 0) { + if(!(outpkt->len = uncompress_packet(outpkt->data, inpkt->data, inpkt->len, n->incompression))) { ifdebug(TRAFFIC) logger(LOG_ERR, "Error while uncompressing packet from %s (%s)", n->name, n->hostname); return; @@ -414,7 +413,7 @@ static void receive_udppacket(node_t *n, vpn_packet_t *inpkt) { } } -void receive_tcppacket(connection_t *c, const char *buffer, int len) { +void receive_tcppacket(connection_t *c, const char *buffer, length_t len) { vpn_packet_t outpkt; if(len > sizeof(outpkt.data)) { @@ -488,7 +487,7 @@ static void send_udppacket(node_t *n, vpn_packet_t *origpkt) { if(n->outcompression) { outpkt = pkt[nextpkt++]; - if((outpkt->len = compress_packet(outpkt->data, inpkt->data, inpkt->len, n->outcompression)) < 0) { + if(!(outpkt->len = compress_packet(outpkt->data, inpkt->data, inpkt->len, n->outcompression))) { ifdebug(TRAFFIC) logger(LOG_ERR, "Error while compressing packet to %s (%s)", n->name, n->hostname); return; @@ -761,16 +760,19 @@ void handle_incoming_vpn_data(int sock) { socklen_t fromlen = sizeof(from); node_t *n; - pkt.len = recvfrom(listen_socket[sock].udp, (char *) &pkt.seqno, MAXSIZE, 0, &from.sa, &fromlen); + ssize_t len = recvfrom(listen_socket[sock].udp, (char *) &pkt.seqno, MAXSIZE, 0, &from.sa, &fromlen); - if(pkt.len < 0) { - if(!sockwouldblock(sockerrno)) { + if(len <= 0 || len > UINT16_MAX) { + if(len >= 0) { + logger(LOG_ERR, "Receiving packet with invalid size"); + } else if(!sockwouldblock(sockerrno)) { logger(LOG_ERR, "Receiving packet failed: %s", sockstrerror(sockerrno)); } return; } + pkt.len = len; sockaddrunmap(&from); /* Some braindead IPv6 implementations do stupid things. */ n = lookup_node_udp(&from); diff --git a/src/net_setup.c b/src/net_setup.c index 8eb3e605..13719f52 100644 --- a/src/net_setup.c +++ b/src/net_setup.c @@ -76,7 +76,7 @@ bool read_rsa_public_key(connection_t *c) { /* First, check for simple PublicKey statement */ if(get_config_string(lookup_config(c->config_tree, "PublicKey"), &key)) { - if(BN_hex2bn(&n, key) != strlen(key)) { + if((size_t)BN_hex2bn(&n, key) != strlen(key)) { free(key); logger(LOG_ERR, "Invalid PublicKey for %s!", c->name); return false; @@ -191,7 +191,7 @@ static bool read_rsa_private_key(void) { myself->connection->rsa_key = RSA_new(); // RSA_blinding_on(myself->connection->rsa_key, NULL); - if(BN_hex2bn(&d, key) != strlen(key)) { + if((size_t)BN_hex2bn(&d, key) != strlen(key)) { logger(LOG_ERR, "Invalid PrivateKey for myself!"); free(key); return false; @@ -205,7 +205,7 @@ static bool read_rsa_private_key(void) { return false; } - if(BN_hex2bn(&n, pubkey) != strlen(pubkey)) { + if((size_t)BN_hex2bn(&n, pubkey) != strlen(pubkey)) { free(pubkey); BN_free(d); logger(LOG_ERR, "Invalid PublicKey for myself!"); @@ -388,8 +388,8 @@ static bool setup_myself(void) { char *address = NULL; char *proxy = NULL; char *space; - char *envp[5] = {NULL}; - struct addrinfo *ai, *aip, hint = {0}; + char *envp[5] = {}; + struct addrinfo *ai, *aip, hint = {}; bool choice; int i, err; int replaywin_int; @@ -1068,7 +1068,7 @@ bool setup_network(void) { void close_network_connections(void) { avl_node_t *node, *next; connection_t *c; - char *envp[5] = {NULL}; + char *envp[5] = {}; int i; for(node = connection_tree->head; node; node = next) { diff --git a/src/netutl.c b/src/netutl.c index abe3d876..3c2a77df 100644 --- a/src/netutl.c +++ b/src/netutl.c @@ -33,7 +33,7 @@ bool hostnames = false; Return NULL on failure. */ struct addrinfo *str2addrinfo(const char *address, const char *service, int socktype) { - struct addrinfo *ai = NULL, hint = {0}; + struct addrinfo *ai = NULL, hint = {}; int err; hint.ai_family = addressfamily; @@ -55,7 +55,7 @@ struct addrinfo *str2addrinfo(const char *address, const char *service, int sock } sockaddr_t str2sockaddr(const char *address, const char *port) { - struct addrinfo *ai = NULL, hint = {0}; + struct addrinfo *ai = NULL, hint = {}; sockaddr_t result; int err; diff --git a/src/node.c b/src/node.c index 720f081a..12bc38f7 100644 --- a/src/node.c +++ b/src/node.c @@ -140,7 +140,7 @@ void node_del(node_t *n) { } node_t *lookup_node(char *name) { - node_t n = {NULL}; + node_t n = {}; n.name = name; @@ -148,7 +148,7 @@ node_t *lookup_node(char *name) { } node_t *lookup_node_udp(const sockaddr_t *sa) { - node_t n = {NULL}; + node_t n = {}; n.address = *sa; n.name = NULL; diff --git a/src/process.c b/src/process.c index 4c85ce2f..13d10071 100644 --- a/src/process.c +++ b/src/process.c @@ -505,6 +505,7 @@ bool execute_script(const char *name, char **envp) { #ifndef HAVE_MINGW static RETSIGTYPE sigterm_handler(int a) { + (void)a; logger(LOG_NOTICE, "Got %s signal", "TERM"); if(running) { @@ -515,6 +516,7 @@ static RETSIGTYPE sigterm_handler(int a) { } static RETSIGTYPE sigquit_handler(int a) { + (void)a; logger(LOG_NOTICE, "Got %s signal", "QUIT"); if(running) { @@ -553,11 +555,13 @@ static RETSIGTYPE fatal_signal_handler(int a) { } static RETSIGTYPE sighup_handler(int a) { + (void)a; logger(LOG_NOTICE, "Got %s signal", "HUP"); sighup = true; } static RETSIGTYPE sigint_handler(int a) { + (void)a; static int saved_debug_level = -1; logger(LOG_NOTICE, "Got %s signal", "INT"); @@ -577,15 +581,18 @@ static RETSIGTYPE sigint_handler(int a) { } static RETSIGTYPE sigalrm_handler(int a) { + (void)a; logger(LOG_NOTICE, "Got %s signal", "ALRM"); sigalrm = true; } static RETSIGTYPE sigusr1_handler(int a) { + (void)a; dump_connections(); } static RETSIGTYPE sigusr2_handler(int a) { + (void)a; devops.dump_stats(); dump_nodes(); dump_edges(); @@ -593,14 +600,17 @@ static RETSIGTYPE sigusr2_handler(int a) { } static RETSIGTYPE sigwinch_handler(int a) { + (void)a; do_purge = true; } static RETSIGTYPE unexpected_signal_handler(int a) { + (void)a; logger(LOG_WARNING, "Got unexpected signal %d (%s)", a, strsignal(a)); } static RETSIGTYPE ignore_signal_handler(int a) { + (void)a; ifdebug(SCARY_THINGS) logger(LOG_DEBUG, "Ignored signal %d (%s)", a, strsignal(a)); } diff --git a/src/protocol.c b/src/protocol.c index 144def21..f43fccd4 100644 --- a/src/protocol.c +++ b/src/protocol.c @@ -80,7 +80,7 @@ bool send_request(connection_t *c, const char *format, ...) { buffer[sizeof(buffer) - 1] = 0; va_end(args); - if(len < 0 || len > sizeof(buffer) - 1) { + if(len < 0 || (size_t)len > sizeof(buffer) - 1) { logger(LOG_ERR, "Output buffer overflow while sending request to %s (%s)", c->name, c->hostname); return false; @@ -193,7 +193,7 @@ void exit_requests(void) { } bool seen_request(char *request) { - past_request_t *new, p = {NULL}; + past_request_t *new, p = {}; p.request = request; diff --git a/src/protocol_auth.c b/src/protocol_auth.c index 6d1435bc..95bb7517 100644 --- a/src/protocol_auth.c +++ b/src/protocol_auth.c @@ -239,7 +239,7 @@ bool metakey_h(connection_t *c) { /* Check if the length of the meta key is all right */ - if(strlen(buffer) != len * 2) { + if(strlen(buffer) != (size_t)len * 2) { logger(LOG_ERR, "Possible intruder %s (%s): %s", c->name, c->hostname, "wrong keylength"); return false; } @@ -372,7 +372,7 @@ bool challenge_h(connection_t *c) { /* Check if the length of the challenge is all right */ - if(strlen(buffer) != len * 2) { + if(strlen(buffer) != (size_t)len * 2) { logger(LOG_ERR, "Possible intruder %s (%s): %s", c->name, c->hostname, "wrong challenge length"); return false; @@ -442,7 +442,7 @@ bool chal_reply_h(connection_t *c) { /* Check if the length of the hash is all right */ - if(strlen(hishash) != EVP_MD_size(c->outdigest) * 2) { + if(strlen(hishash) != (size_t)EVP_MD_size(c->outdigest) * 2) { logger(LOG_ERR, "Possible intruder %s (%s): %s", c->name, c->hostname, "wrong challenge reply length"); return false; diff --git a/src/protocol_misc.c b/src/protocol_misc.c index c08a0d16..22b204d9 100644 --- a/src/protocol_misc.c +++ b/src/protocol_misc.c @@ -146,9 +146,9 @@ bool send_tcppacket(connection_t *c, const vpn_packet_t *packet) { } bool tcppacket_h(connection_t *c) { - short int len; + length_t len; - if(sscanf(c->buffer, "%*d %hd", &len) != 1) { + if(sscanf(c->buffer, "%*d %hu", &len) != 1) { logger(LOG_ERR, "Got bad %s from %s (%s)", "PACKET", c->name, c->hostname); return false; diff --git a/src/protocol_subnet.c b/src/protocol_subnet.c index 0bdcb730..01aed64e 100644 --- a/src/protocol_subnet.c +++ b/src/protocol_subnet.c @@ -46,7 +46,7 @@ bool add_subnet_h(connection_t *c) { char subnetstr[MAX_STRING_SIZE]; char name[MAX_STRING_SIZE]; node_t *owner; - subnet_t s = {NULL}, *new, *old; + subnet_t s = {}, *new, *old; if(sscanf(c->buffer, "%*d %*x " MAX_STRING " " MAX_STRING, name, subnetstr) != 2) { logger(LOG_ERR, "Got bad %s from %s (%s)", "ADD_SUBNET", c->name, @@ -160,7 +160,7 @@ bool del_subnet_h(connection_t *c) { char subnetstr[MAX_STRING_SIZE]; char name[MAX_STRING_SIZE]; node_t *owner; - subnet_t s = {NULL}, *find; + subnet_t s = {}, *find; if(sscanf(c->buffer, "%*d %*x " MAX_STRING " " MAX_STRING, name, subnetstr) != 2) { logger(LOG_ERR, "Got bad %s from %s (%s)", "DEL_SUBNET", c->name, diff --git a/src/proxy.c b/src/proxy.c index 882871cc..979626c1 100644 --- a/src/proxy.c +++ b/src/proxy.c @@ -79,6 +79,7 @@ bool send_proxyrequest(connection_t *c) { return false; } + // fallthrough case PROXY_SOCKS4A: { if(c->address.sa.sa_family != AF_INET && c->address.sa.sa_family != AF_UNKNOWN) { logger(LOG_ERR, "Can only connect to IPv4 addresses or hostnames through a SOCKS 4a proxy!"); @@ -215,7 +216,7 @@ bool send_proxyrequest(connection_t *c) { } } -int receive_proxy_meta(connection_t *c, int start, int lenin) { +int receive_proxy_meta(connection_t *c) { switch(proxytype) { case PROXY_SOCKS4: case PROXY_SOCKS4A: diff --git a/src/proxy.h b/src/proxy.h index 9eb2903b..a96fc3df 100644 --- a/src/proxy.h +++ b/src/proxy.h @@ -38,6 +38,6 @@ extern char *proxyuser; extern char *proxypass; extern bool send_proxyrequest(struct connection_t *c); -extern int receive_proxy_meta(struct connection_t *c, int start, int lenin); +extern int receive_proxy_meta(struct connection_t *c); #endif diff --git a/src/route.c b/src/route.c index 7530e429..8b7a13c8 100644 --- a/src/route.c +++ b/src/route.c @@ -116,8 +116,8 @@ static void swap_mac_addresses(vpn_packet_t *packet) { /* RFC 792 */ static void route_ipv4_unreachable(node_t *source, vpn_packet_t *packet, length_t ether_size, uint8_t type, uint8_t code) { - struct ip ip = {0}; - struct icmp icmp = {0}; + struct ip ip = {}; + struct icmp icmp = {}; struct in_addr ip_src; struct in_addr ip_dst; @@ -218,7 +218,7 @@ static void route_ipv4_unreachable(node_t *source, vpn_packet_t *packet, length_ static void route_ipv6_unreachable(node_t *source, vpn_packet_t *packet, length_t ether_size, uint8_t type, uint8_t code) { struct ip6_hdr ip6; - struct icmp6_hdr icmp6 = {0}; + struct icmp6_hdr icmp6 = {}; uint16_t checksum; struct { diff --git a/src/tincd.c b/src/tincd.c index 5b6b3294..a8b13ecb 100644 --- a/src/tincd.c +++ b/src/tincd.c @@ -363,6 +363,8 @@ static bool parse_options(int argc, char **argv) { /* This function prettyprints the key generation process */ static int indicator(int a, int b, BN_GENCB *cb) { + (void)cb; + switch(a) { case 0: fprintf(stderr, ".");