From 1c475ecb575367a6b3f9328b0f643ad636155341 Mon Sep 17 00:00:00 2001 From: Guus Sliepen Date: Sat, 6 Oct 2018 23:31:05 +0200 Subject: [PATCH] Fix all warnings when compiling with -Wall -W -pedantic. --- src/buffer.c | 12 +-- src/buffer.h | 14 +-- src/chacha-poly1305/chacha-poly1305.c | 9 +- src/conf.c | 4 +- src/dummy_device.c | 2 + src/ed25519/ecdsa.c | 4 +- src/ed25519/ecdsagen.c | 3 +- src/event.c | 2 + src/fsck.c | 2 + src/ifconfig.c | 4 +- src/info.c | 4 + src/invitation.c | 35 ++++-- src/invitation.h | 1 - src/linux/device.c | 4 +- src/logger.c | 5 +- src/meta.c | 23 ++-- src/meta.h | 6 +- src/multicast_device.c | 2 +- src/net.c | 2 +- src/net.h | 6 +- src/net_packet.c | 42 ++++---- src/net_setup.c | 4 +- src/net_socket.c | 3 + src/netutl.c | 2 +- src/node.c | 6 +- src/openssl/crypto.c | 4 +- src/openssl/prf.c | 4 +- src/openssl/rsa.c | 8 +- src/openssl/rsagen.c | 2 + src/protocol.c | 5 +- src/protocol_auth.c | 6 +- src/protocol_edge.c | 2 +- src/protocol_key.c | 13 ++- src/protocol_misc.c | 4 + src/protocol_subnet.c | 4 +- src/route.c | 1 + src/splay_tree.c | 2 +- src/sptps.c | 21 +++- src/sptps_keypair.c | 4 + src/sptps_test.c | 14 ++- src/subnet_parse.c | 2 +- src/tincctl.c | 150 ++++++++++++++++---------- src/top.c | 2 +- src/upnp.c | 2 + src/utils.c | 22 ++-- src/utils.h | 10 +- 46 files changed, 303 insertions(+), 180 deletions(-) diff --git a/src/buffer.c b/src/buffer.c index a9e79aa9..60adec86 100644 --- a/src/buffer.c +++ b/src/buffer.c @@ -22,7 +22,7 @@ #include "buffer.h" #include "xalloc.h" -void buffer_compact(buffer_t *buffer, int maxsize) { +void buffer_compact(buffer_t *buffer, uint32_t maxsize) { if(buffer->len >= maxsize || buffer->offset / 7 > buffer->len / 8) { memmove(buffer->data, buffer->data + buffer->offset, buffer->len - buffer->offset); buffer->len -= buffer->offset; @@ -32,7 +32,7 @@ void buffer_compact(buffer_t *buffer, int maxsize) { // Make sure we can add size bytes to the buffer, and return a pointer to the start of those bytes. -char *buffer_prepare(buffer_t *buffer, int size) { +char *buffer_prepare(buffer_t *buffer, uint32_t size) { if(!buffer->data) { buffer->maxlen = size; buffer->data = xmalloc(size); @@ -58,13 +58,13 @@ char *buffer_prepare(buffer_t *buffer, int size) { // Copy data into the buffer. -void buffer_add(buffer_t *buffer, const char *data, int size) { +void buffer_add(buffer_t *buffer, const char *data, uint32_t size) { memcpy(buffer_prepare(buffer, size), data, size); } // Remove given number of bytes from the buffer, return a pointer to the start of them. -static char *buffer_consume(buffer_t *buffer, int size) { +static char *buffer_consume(buffer_t *buffer, uint32_t size) { char *start = buffer->data + buffer->offset; buffer->offset += size; @@ -86,14 +86,14 @@ char *buffer_readline(buffer_t *buffer) { return NULL; } - int len = newline + 1 - (buffer->data + buffer->offset); + uint32_t len = newline + 1 - (buffer->data + buffer->offset); *newline = 0; return buffer_consume(buffer, len); } // Check if we have enough bytes in the buffer, and if so, return a pointer to the start of them. -char *buffer_read(buffer_t *buffer, int size) { +char *buffer_read(buffer_t *buffer, uint32_t size) { if(buffer->len - buffer->offset < size) { return NULL; } diff --git a/src/buffer.h b/src/buffer.h index 53522b69..b25c8adc 100644 --- a/src/buffer.h +++ b/src/buffer.h @@ -3,16 +3,16 @@ typedef struct buffer_t { char *data; - int maxlen; - int len; - int offset; + uint32_t maxlen; + uint32_t len; + uint32_t offset; } buffer_t; -extern void buffer_compact(buffer_t *buffer, int maxsize); -extern char *buffer_prepare(buffer_t *buffer, int size); -extern void buffer_add(buffer_t *buffer, const char *data, int size); +extern void buffer_compact(buffer_t *buffer, uint32_t maxsize); +extern char *buffer_prepare(buffer_t *buffer, uint32_t size); +extern void buffer_add(buffer_t *buffer, const char *data, uint32_t size); extern char *buffer_readline(buffer_t *buffer); -extern char *buffer_read(buffer_t *buffer, int size); +extern char *buffer_read(buffer_t *buffer, uint32_t size); extern void buffer_clear(buffer_t *buffer); #endif diff --git a/src/chacha-poly1305/chacha-poly1305.c b/src/chacha-poly1305/chacha-poly1305.c index b5dab4e4..a74c5024 100644 --- a/src/chacha-poly1305/chacha-poly1305.c +++ b/src/chacha-poly1305/chacha-poly1305.c @@ -20,7 +20,8 @@ void chacha_poly1305_exit(chacha_poly1305_ctx_t *ctx) { free(ctx); } -bool chacha_poly1305_set_key(chacha_poly1305_ctx_t *ctx, const void *key) { +bool chacha_poly1305_set_key(chacha_poly1305_ctx_t *ctx, const void *vkey) { + const uint8_t *key = vkey; chacha_keysetup(&ctx->main_ctx, key, 256); chacha_keysetup(&ctx->header_ctx, key + 32, 256); return true; @@ -39,10 +40,11 @@ static void put_u64(void *vp, uint64_t v) { p[7] = (uint8_t) v & 0xff; } -bool chacha_poly1305_encrypt(chacha_poly1305_ctx_t *ctx, uint64_t seqnr, const void *indata, size_t inlen, void *outdata, size_t *outlen) { +bool chacha_poly1305_encrypt(chacha_poly1305_ctx_t *ctx, uint64_t seqnr, const void *indata, size_t inlen, void *voutdata, size_t *outlen) { uint8_t seqbuf[8]; const uint8_t one[8] = { 1, 0, 0, 0, 0, 0, 0, 0 }; /* NB little-endian */ uint8_t poly_key[POLY1305_KEYLEN]; + uint8_t *outdata = voutdata; /* * Run ChaCha20 once to generate the Poly1305 key. The IV is the @@ -66,10 +68,11 @@ bool chacha_poly1305_encrypt(chacha_poly1305_ctx_t *ctx, uint64_t seqnr, const v return true; } -bool chacha_poly1305_decrypt(chacha_poly1305_ctx_t *ctx, uint64_t seqnr, const void *indata, size_t inlen, void *outdata, size_t *outlen) { +bool chacha_poly1305_decrypt(chacha_poly1305_ctx_t *ctx, uint64_t seqnr, const void *vindata, size_t inlen, void *outdata, size_t *outlen) { uint8_t seqbuf[8]; const uint8_t one[8] = { 1, 0, 0, 0, 0, 0, 0, 0 }; /* NB little-endian */ uint8_t expected_tag[POLY1305_TAGLEN], poly_key[POLY1305_KEYLEN]; + const uint8_t *indata = vindata; /* * Run ChaCha20 once to generate the Poly1305 key. The IV is the diff --git a/src/conf.c b/src/conf.c index 57065701..0b84ad71 100644 --- a/src/conf.c +++ b/src/conf.c @@ -203,7 +203,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 = {0}; if(!cfg) { return false; @@ -433,7 +433,7 @@ bool read_server_config(void) { // And we try to read the ones that end with ".conf" if(l > 5 && !strcmp(".conf", & ep->d_name[ l - 5 ])) { - if(snprintf(fname, sizeof(fname), "%s" SLASH "%s", dname, ep->d_name) >= sizeof(fname)) { + if((size_t)snprintf(fname, sizeof(fname), "%s" SLASH "%s", dname, ep->d_name) >= sizeof(fname)) { logger(DEBUG_ALWAYS, LOG_ERR, "Pathname too long: %s/%s", dname, ep->d_name); return false; } diff --git a/src/dummy_device.c b/src/dummy_device.c index 80232e1e..15f0654f 100644 --- a/src/dummy_device.c +++ b/src/dummy_device.c @@ -37,10 +37,12 @@ static void close_device(void) { } static bool read_packet(vpn_packet_t *packet) { + (void)packet; return false; } static bool write_packet(vpn_packet_t *packet) { + (void)packet; return true; } diff --git a/src/ed25519/ecdsa.c b/src/ed25519/ecdsa.c index 79532c8f..4bd71556 100644 --- a/src/ed25519/ecdsa.c +++ b/src/ed25519/ecdsa.c @@ -63,10 +63,11 @@ char *ecdsa_get_base64_public_key(ecdsa_t *ecdsa) { // Read PEM ECDSA keys -static bool read_pem(FILE *fp, const char *type, void *buf, size_t size) { +static bool read_pem(FILE *fp, const char *type, void *vbuf, size_t size) { char line[1024]; bool data = false; size_t typelen = strlen(type); + char *buf = vbuf; while(fgets(line, sizeof(line), fp)) { if(!data) { @@ -143,6 +144,7 @@ ecdsa_t *ecdsa_read_pem_private_key(FILE *fp) { } size_t ecdsa_size(ecdsa_t *ecdsa) { + (void)ecdsa; return 64; } diff --git a/src/ed25519/ecdsagen.c b/src/ed25519/ecdsagen.c index 9a1de1e7..ede51367 100644 --- a/src/ed25519/ecdsagen.c +++ b/src/ed25519/ecdsagen.c @@ -46,9 +46,10 @@ ecdsa_t *ecdsa_generate(void) { // Write PEM ECDSA keys -static bool write_pem(FILE *fp, const char *type, void *buf, size_t size) { +static bool write_pem(FILE *fp, const char *type, void *vbuf, size_t size) { fprintf(fp, "-----BEGIN %s-----\n", type); + char *buf = vbuf; char base64[65]; while(size) { diff --git a/src/event.c b/src/event.c index 8c7de479..47adb181 100644 --- a/src/event.c +++ b/src/event.c @@ -237,6 +237,8 @@ static void signal_handler(int signum) { } static void signalio_handler(void *data, int flags) { + (void)data; + (void)flags; unsigned char signum; if(read(pipefd[0], &signum, 1) != 1) { diff --git a/src/fsck.c b/src/fsck.c index e17b46c5..e19f03ff 100644 --- a/src/fsck.c +++ b/src/fsck.c @@ -88,6 +88,8 @@ static int strtailcmp(const char *str, const char *tail) { } static void check_conffile(const char *fname, bool server) { + (void)server; + FILE *f = fopen(fname, "r"); if(!f) { diff --git a/src/ifconfig.c b/src/ifconfig.c index 3723c97a..4b47ad13 100644 --- a/src/ifconfig.c +++ b/src/ifconfig.c @@ -86,7 +86,7 @@ bool ifconfig_footer(FILE *out) { static subnet_t ipv4, ipv6; void ifconfig_address(FILE *out, const char *value) { - subnet_t address = {NULL}; + subnet_t address = {0}; char address_str[MAXNETSTR]; if(!str2net(&address, value) || !net2str(address_str, sizeof(address_str), &address)) { @@ -168,7 +168,7 @@ void ifconfig_address(FILE *out, const char *value) { } void ifconfig_route(FILE *out, const char *value) { - subnet_t subnet = {NULL}, gateway = {NULL}; + subnet_t subnet = {0}, gateway = {0}; char subnet_str[MAXNETSTR] = "", gateway_str[MAXNETSTR] = ""; char *sep = strchr(value, ' '); diff --git a/src/info.c b/src/info.c index 562b5ff2..758c0d1f 100644 --- a/src/info.c +++ b/src/info.c @@ -28,10 +28,14 @@ #include "xalloc.h" void logger(int level, int priority, const char *format, ...) { + (void)level; + (void)priority; va_list ap; + va_start(ap, format); vfprintf(stderr, format, ap); va_end(ap); + fputc('\n', stderr); } diff --git a/src/invitation.c b/src/invitation.c index c3072cf2..500f2434 100644 --- a/src/invitation.c +++ b/src/invitation.c @@ -356,7 +356,7 @@ int cmd_invite(int argc, char *argv[]) { char invname[PATH_MAX]; struct stat st; - if(snprintf(invname, sizeof(invname), "%s" SLASH "%s", filename, ent->d_name) >= sizeof(invname)) { + if((size_t)snprintf(invname, sizeof(invname), "%s" SLASH "%s", filename, ent->d_name) >= sizeof(invname)) { fprintf(stderr, "Filename too long: %s" SLASH "%s\n", filename, ent->d_name); continue; } @@ -555,7 +555,7 @@ static char *get_line(const char **data) { static char line[1024]; const char *end = strchr(*data, '\n'); - size_t len = end ? end - *data : strlen(*data); + size_t len = end ? (size_t)(end - *data) : strlen(*data); if(len >= sizeof(line)) { fprintf(stderr, "Maximum line length exceeded!\n"); @@ -635,7 +635,7 @@ static char *grep(const char *data, const char *var) { return xstrdup(p); } - if(e - p >= sizeof(value)) { + if((size_t)(e - p) >= sizeof(value)) { fprintf(stderr, "Maximum line length exceeded!\n"); return NULL; } @@ -646,13 +646,18 @@ static char *grep(const char *data, const char *var) { } static bool finalize_join(void) { - const char *name = get_value(data, "Name"); + const char *temp_name = get_value(data, "Name"); - if(!name) { + if(!temp_name) { fprintf(stderr, "No Name found in invitation!\n"); return false; } + size_t len = strlen(temp_name); + char name[len + 1]; + memcpy(name, temp_name, len); + name[len] = 0; + if(!check_id(name)) { fprintf(stderr, "Invalid Name found in invitation!\n"); return false; @@ -962,7 +967,7 @@ ask_netname: char newbase[PATH_MAX]; - if(snprintf(newbase, sizeof(newbase), CONFDIR SLASH "tinc" SLASH "%s", line) >= sizeof(newbase)) { + if((size_t)snprintf(newbase, sizeof(newbase), CONFDIR SLASH "tinc" SLASH "%s", line) >= sizeof(newbase)) { fprintf(stderr, "Filename too long: " CONFDIR SLASH "tinc" SLASH "%s\n", line); goto ask_netname; } @@ -1007,7 +1012,13 @@ ask_netname: if(response == 'e') { char *command; #ifndef HAVE_MINGW - xasprintf(&command, "\"%s\" \"%s\"", getenv("VISUAL") ? : getenv("EDITOR") ? : "vi", filename); + const char *editor = getenv("VISUAL"); + if (!editor) + editor = getenv("EDITOR"); + if (!editor) + editor = "vi"; + + xasprintf(&command, "\"%s\" \"%s\"", editor, filename); #else xasprintf(&command, "edit \"%s\"", filename); #endif @@ -1044,7 +1055,11 @@ ask_netname: } -static bool invitation_send(void *handle, uint8_t type, const void *data, size_t len) { +static bool invitation_send(void *handle, uint8_t type, const void *vdata, size_t len) { + (void)handle; + (void)type; + const char *data = vdata; + while(len) { int result = send(sock, data, len, 0); @@ -1062,6 +1077,8 @@ static bool invitation_send(void *handle, uint8_t type, const void *data, size_t } static bool invitation_receive(void *handle, uint8_t type, const void *msg, uint16_t len) { + (void)handle; + switch(type) { case SPTPS_HANDSHAKE: return sptps_send_record(&sptps, 0, cookie, sizeof(cookie)); @@ -1240,7 +1257,7 @@ next: // Tell him we have an invitation, and give him our throw-away key. int len = snprintf(line, sizeof(line), "0 ?%s %d.%d\n", b64key, PROT_MAJOR, PROT_MINOR); - if(len <= 0 || len >= sizeof(line)) { + if(len <= 0 || (size_t)len >= sizeof(line)) { abort(); } diff --git a/src/invitation.h b/src/invitation.h index 621baab9..6517fe84 100644 --- a/src/invitation.h +++ b/src/invitation.h @@ -20,7 +20,6 @@ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ -bool recvdata(int fd, char *data, size_t len); int cmd_invite(int argc, char *argv[]); int cmd_join(int argc, char *argv[]); diff --git a/src/linux/device.c b/src/linux/device.c index 0abafa9d..94e223f7 100644 --- a/src/linux/device.c +++ b/src/linux/device.c @@ -67,7 +67,7 @@ static bool setup_device(void) { fcntl(device_fd, F_SETFD, FD_CLOEXEC); #endif - struct ifreq ifr = {{{0}}}; + struct ifreq ifr = {0}; get_config_string(lookup_config(config_tree, "DeviceType"), &type); @@ -119,7 +119,7 @@ static bool setup_device(void) { logger(DEBUG_ALWAYS, LOG_INFO, "%s is a %s", device, device_info); if(ifr.ifr_flags & IFF_TAP) { - struct ifreq ifr_mac = {{{0}}}; + struct ifreq ifr_mac = {0}; if(!ioctl(device_fd, SIOCGIFHWADDR, &ifr_mac)) { memcpy(mymac.x, ifr_mac.ifr_hwaddr.sa_data, ETH_ALEN); diff --git a/src/logger.c b/src/logger.c index bcadae11..062f7598 100644 --- a/src/logger.c +++ b/src/logger.c @@ -130,7 +130,7 @@ void logger(int level, int priority, const char *format, ...) { message[sizeof(message) - 1] = 0; va_end(ap); - if(len > 0 && len < sizeof(message) - 1 && message[len - 1] == '\n') { + if(len > 0 && (size_t)len < sizeof(message) - 1 && message[len - 1] == '\n') { message[len - 1] = 0; } @@ -138,13 +138,14 @@ void logger(int level, int priority, const char *format, ...) { } static void sptps_logger(sptps_t *s, int s_errno, const char *format, va_list ap) { + (void)s_errno; char message[1024]; size_t msglen = sizeof(message); int len = vsnprintf(message, msglen, format, ap); message[sizeof(message) - 1] = 0; - if(len > 0 && len < sizeof(message) - 1) { + if(len > 0 && (size_t)len < sizeof(message) - 1) { if(message[len - 1] == '\n') { message[--len] = 0; } diff --git a/src/meta.c b/src/meta.c index 5b47aa66..0089ac82 100644 --- a/src/meta.c +++ b/src/meta.c @@ -35,6 +35,7 @@ #endif bool send_meta_sptps(void *handle, uint8_t type, const void *buffer, size_t length) { + (void)type; connection_t *c = handle; if(!c) { @@ -48,13 +49,13 @@ bool send_meta_sptps(void *handle, uint8_t type, const void *buffer, size_t leng return true; } -bool send_meta(connection_t *c, const char *buffer, int length) { +bool send_meta(connection_t *c, const char *buffer, size_t length) { if(!c) { logger(DEBUG_ALWAYS, LOG_ERR, "send_meta() called with NULL pointer!"); abort(); } - logger(DEBUG_META, LOG_DEBUG, "Sending %d bytes of metadata to %s (%s)", length, + logger(DEBUG_META, LOG_DEBUG, "Sending %lu bytes of metadata to %s (%s)", (unsigned long)length, c->name, c->hostname); if(c->protocol_minor >= 2) { @@ -92,13 +93,13 @@ bool send_meta(connection_t *c, const char *buffer, int length) { return true; } -void send_meta_raw(connection_t *c, const char *buffer, int length) { +void send_meta_raw(connection_t *c, const char *buffer, size_t length) { if(!c) { logger(DEBUG_ALWAYS, LOG_ERR, "send_meta() called with NULL pointer!"); abort(); } - logger(DEBUG_META, LOG_DEBUG, "Sending %d bytes of raw metadata to %s (%s)", length, + logger(DEBUG_META, LOG_DEBUG, "Sending %lu bytes of raw metadata to %s (%s)", (unsigned long)length, c->name, c->hostname); buffer_add(&c->outbuf, buffer, length); @@ -106,7 +107,7 @@ void send_meta_raw(connection_t *c, const char *buffer, int length) { io_set(&c->io, IO_READ | IO_WRITE); } -void broadcast_meta(connection_t *from, const char *buffer, int length) { +void broadcast_meta(connection_t *from, const char *buffer, size_t length) { for list_each(connection_t, c, connection_list) if(c != from && c->edge) { send_meta(c, buffer, length); @@ -158,7 +159,7 @@ bool receive_meta_sptps(void *handle, uint8_t type, const void *vdata, uint16_t } bool receive_meta(connection_t *c) { - int inlen; + ssize_t inlen; char inbuf[MAXBUFSIZE]; char *bufp = inbuf, *endp; @@ -197,7 +198,7 @@ bool receive_meta(connection_t *c) { /* Are we receiving a SPTPS packet? */ if(c->sptpslen) { - int len = MIN(inlen, c->sptpslen - c->inbuf.len); + ssize_t len = MIN(inlen, c->sptpslen - c->inbuf.len); buffer_add(&c->inbuf, bufp, len); char *sptpspacket = buffer_read(&c->inbuf, c->sptpslen); @@ -218,7 +219,7 @@ bool receive_meta(connection_t *c) { } if(c->protocol_minor >= 2) { - int len = sptps_receive_data(&c->sptps, bufp, inlen); + size_t len = sptps_receive_data(&c->sptps, bufp, inlen); if(!len) { return false; @@ -247,8 +248,8 @@ bool receive_meta(connection_t *c) { return false; #else - if(inlen > c->inbudget) { - logger(DEBUG_META, LOG_ERR, "yte limit exceeded for decryption from %s (%s)", c->name, c->hostname); + if((size_t)inlen > c->inbudget) { + logger(DEBUG_META, LOG_ERR, "Byte limit exceeded for decryption from %s (%s)", c->name, c->hostname); return false; } else { c->inbudget -= inlen; @@ -256,7 +257,7 @@ bool receive_meta(connection_t *c) { size_t outlen = inlen; - if(!cipher_decrypt(c->incipher, bufp, inlen, buffer_prepare(&c->inbuf, inlen), &outlen, false) || inlen != outlen) { + if(!cipher_decrypt(c->incipher, bufp, inlen, buffer_prepare(&c->inbuf, inlen), &outlen, false) || (size_t)inlen != outlen) { logger(DEBUG_ALWAYS, LOG_ERR, "Error while decrypting metadata from %s (%s)", c->name, c->hostname); return false; diff --git a/src/meta.h b/src/meta.h index 1c134ff1..dcf2419b 100644 --- a/src/meta.h +++ b/src/meta.h @@ -23,11 +23,11 @@ #include "connection.h" -extern bool send_meta(struct connection_t *c, const char *buffer, int length); -extern void send_meta_raw(struct connection_t *c, const char *buffer, int length); +extern bool send_meta(struct connection_t *c, const char *buffer, size_t length); +extern void send_meta_raw(struct connection_t *c, const char *buffer, size_t length); extern bool send_meta_sptps(void *handle, uint8_t type, const void *data, size_t length); extern bool receive_meta_sptps(void *handle, uint8_t type, const void *data, uint16_t length); -extern void broadcast_meta(struct connection_t *from, const char *buffer, int length); +extern void broadcast_meta(struct connection_t *from, const char *buffer, size_t length); extern bool receive_meta(struct connection_t *c); #endif diff --git a/src/multicast_device.c b/src/multicast_device.c index 99f26ca9..e9607f0d 100644 --- a/src/multicast_device.c +++ b/src/multicast_device.c @@ -32,7 +32,7 @@ static const char *device_info = "multicast socket"; static struct addrinfo *ai = NULL; -static mac_t ignore_src = {{0}}; +static mac_t ignore_src = {0}; static bool setup_device(void) { char *host = NULL; diff --git a/src/net.c b/src/net.c index e9aed34c..75838e00 100644 --- a/src/net.c +++ b/src/net.c @@ -95,7 +95,7 @@ void purge(void) { /* Put a misbehaving connection in the tarpit */ void tarpit(int fd) { static int pits[10] = {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1}; - static int next_pit = 0; + static unsigned int next_pit = 0; if(pits[next_pit] != -1) { closesocket(pits[next_pit]); diff --git a/src/net.h b/src/net.h index aaf29b6f..8a74d859 100644 --- a/src/net.h +++ b/src/net.h @@ -56,7 +56,7 @@ typedef struct node_id_t { uint8_t x[6]; } node_id_t; -typedef short length_t; +typedef uint16_t length_t; typedef uint32_t seqno_t; #define AF_UNKNOWN 255 @@ -190,8 +190,8 @@ extern int setup_vpn_in_socket(const sockaddr_t *sa); extern bool send_sptps_data(node_t *to, node_t *from, int type, const void *data, size_t len); extern bool receive_sptps_record(void *handle, uint8_t type, const void *data, uint16_t len); extern void send_packet(struct node_t *n, vpn_packet_t *packet); -extern void receive_tcppacket(struct connection_t *c, const char *buffer, int length); -extern bool receive_tcppacket_sptps(struct connection_t *c, const char *buffer, int length); +extern void receive_tcppacket(struct connection_t *c, const char *buffer, size_t length); +extern bool receive_tcppacket_sptps(struct connection_t *c, const char *buffer, size_t length); extern void broadcast_packet(const struct node_t *n, vpn_packet_t *packet); extern char *get_name(void); extern void device_enable(void); diff --git a/src/net_packet.c b/src/net_packet.c index a516b4a9..6b40f2ad 100644 --- a/src/net_packet.c +++ b/src/net_packet.c @@ -216,7 +216,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 @@ -226,18 +226,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) { @@ -252,7 +252,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 @@ -275,13 +275,13 @@ static length_t uncompress_packet(uint8_t *dest, const uint8_t *source, length_t if(inflate(&stream, Z_FINISH) == Z_STREAM_END) { return stream.total_out; } else { - return -1; + return 0; } } #endif - return -1; + return 0; } /* VPN packet I/O */ @@ -305,7 +305,7 @@ static bool try_mac(node_t *n, const vpn_packet_t *inpkt) { return false; #else - if(!n->status.validkey_in || !digest_active(n->indigest) || inpkt->len < sizeof(seqno_t) + digest_length(n->indigest)) { + if(!n->status.validkey_in || !digest_active(n->indigest) || (size_t)inpkt->len < sizeof(seqno_t) + digest_length(n->indigest)) { return false; } @@ -364,7 +364,7 @@ static bool receive_udppacket(node_t *n, vpn_packet_t *inpkt) { /* Check packet length */ - if(inpkt->len < sizeof(seqno_t) + digest_length(n->indigest)) { + if((size_t)inpkt->len < sizeof(seqno_t) + digest_length(n->indigest)) { logger(DEBUG_TRAFFIC, LOG_DEBUG, "Got too short packet from %s (%s)", n->name, n->hostname); return false; @@ -426,7 +426,7 @@ static bool receive_udppacket(node_t *n, vpn_packet_t *inpkt) { return false; } } else { - for(int i = n->received_seqno + 1; i < seqno; i++) { + for(seqno_t i = n->received_seqno + 1; i < seqno; i++) { n->late[(i / 8) % replaywin] |= 1 << i % 8; } } @@ -453,7 +453,7 @@ static bool receive_udppacket(node_t *n, vpn_packet_t *inpkt) { if(n->incompression) { vpn_packet_t *outpkt = pkt[nextpkt++]; - if((outpkt->len = uncompress_packet(DATA(outpkt), DATA(inpkt), inpkt->len, n->incompression)) < 0) { + if(!(outpkt->len = uncompress_packet(DATA(outpkt), DATA(inpkt), inpkt->len, n->incompression))) { logger(DEBUG_TRAFFIC, LOG_ERR, "Error while uncompressing packet from %s (%s)", n->name, n->hostname); return false; @@ -484,7 +484,7 @@ static bool receive_udppacket(node_t *n, vpn_packet_t *inpkt) { #endif } -void receive_tcppacket(connection_t *c, const char *buffer, int len) { +void receive_tcppacket(connection_t *c, const char *buffer, size_t len) { vpn_packet_t outpkt; outpkt.offset = DEFAULT_PACKET_OFFSET; @@ -505,7 +505,7 @@ void receive_tcppacket(connection_t *c, const char *buffer, int len) { receive_packet(c->node, &outpkt); } -bool receive_tcppacket_sptps(connection_t *c, const char *data, int len) { +bool receive_tcppacket_sptps(connection_t *c, const char *data, size_t len) { if(len < sizeof(node_id_t) + sizeof(node_id_t)) { logger(DEBUG_PROTOCOL, LOG_ERR, "Got too short TCP SPTPS packet from %s (%s)", c->name, c->hostname); return false; @@ -596,9 +596,9 @@ static void send_sptps_packet(node_t *n, vpn_packet_t *origpkt) { if(n->outcompression) { outpkt.offset = 0; - int len = compress_packet(DATA(&outpkt) + offset, DATA(origpkt) + offset, origpkt->len - offset, n->outcompression); + length_t len = compress_packet(DATA(&outpkt) + offset, DATA(origpkt) + offset, origpkt->len - offset, n->outcompression); - if(len < 0) { + if(!len) { logger(DEBUG_TRAFFIC, LOG_ERR, "Error while compressing packet to %s (%s)", n->name, n->hostname); } else if(len < origpkt->len - offset) { outpkt.len = len + offset; @@ -753,7 +753,7 @@ static void send_udppacket(node_t *n, vpn_packet_t *origpkt) { if(n->outcompression) { outpkt = pkt[nextpkt++]; - if((outpkt->len = compress_packet(DATA(outpkt), DATA(inpkt), inpkt->len, n->outcompression)) < 0) { + if(!(outpkt->len = compress_packet(DATA(outpkt), DATA(inpkt), inpkt->len, n->outcompression))) { logger(DEBUG_TRAFFIC, LOG_ERR, "Error while compressing packet to %s (%s)", n->name, n->hostname); return; @@ -907,7 +907,7 @@ bool send_sptps_data(node_t *to, node_t *from, int type, const void *data, size_ if(relay_supported) { if(direct) { /* Inform the recipient that this packet was sent directly. */ - node_id_t nullid = {{0}}; + node_id_t nullid = {0}; memcpy(buf_ptr, &nullid, sizeof(nullid)); buf_ptr += sizeof(nullid); } else { @@ -1017,7 +1017,7 @@ bool receive_sptps_record(void *handle, uint8_t type, const void *data, uint16_t if(type & PKT_COMPRESSED) { length_t ulen = uncompress_packet(DATA(&inpkt) + offset, (const uint8_t *)data, len, from->incompression); - if(ulen < 0) { + if(!ulen) { return false; } else { inpkt.len = ulen + offset; @@ -1609,7 +1609,7 @@ static node_t *try_harder(const sockaddr_t *from, const vpn_packet_t *pkt) { static void handle_incoming_vpn_packet(listen_socket_t *ls, vpn_packet_t *pkt, sockaddr_t *addr) { char *hostname; - node_id_t nullid = {{0}}; + node_id_t nullid = {0}; node_t *from, *to; bool direct = false; @@ -1726,6 +1726,8 @@ skip_harder: } void handle_incoming_vpn_data(void *data, int flags) { + (void)data; + (void)flags; listen_socket_t *ls = data; #ifdef HAVE_RECVMMSG @@ -1795,6 +1797,8 @@ void handle_incoming_vpn_data(void *data, int flags) { } void handle_device_data(void *data, int flags) { + (void)data; + (void)flags; vpn_packet_t packet; packet.offset = DEFAULT_PACKET_OFFSET; packet.priority = 0; diff --git a/src/net_setup.c b/src/net_setup.c index d48c2299..ed69808d 100644 --- a/src/net_setup.c +++ b/src/net_setup.c @@ -215,7 +215,7 @@ static bool read_ecdsa_private_key(void) { logger(DEBUG_ALWAYS, LOG_ERR, "Error reading Ed25519 private key file `%s': %s", fname, strerror(errno)); if(errno == ENOENT) { - logger(DEBUG_ALWAYS, LOG_INFO, "Create an Ed25519 keypair with `tinc -n %s generate-ed25519-keys'.", netname ? : "."); + logger(DEBUG_ALWAYS, LOG_INFO, "Create an Ed25519 keypair with `tinc -n %s generate-ed25519-keys'.", netname ? netname : "."); } free(fname); @@ -307,7 +307,7 @@ static bool read_rsa_private_key(void) { fname, strerror(errno)); if(errno == ENOENT) { - logger(DEBUG_ALWAYS, LOG_INFO, "Create an RSA keypair with `tinc -n %s generate-rsa-keys'.", netname ? : "."); + logger(DEBUG_ALWAYS, LOG_INFO, "Create an RSA keypair with `tinc -n %s generate-rsa-keys'.", netname ? netname : "."); } free(fname); diff --git a/src/net_socket.c b/src/net_socket.c index 75b20ec9..dcf8372c 100644 --- a/src/net_socket.c +++ b/src/net_socket.c @@ -624,6 +624,7 @@ begin: } void setup_outgoing_connection(outgoing_t *outgoing, bool verbose) { + (void)verbose; timeout_del(&outgoing->ev); node_t *n = outgoing->node; @@ -655,6 +656,7 @@ remove: new connection */ void handle_new_meta_connection(void *data, int flags) { + (void)flags; listen_socket_t *l = data; connection_t *c; sockaddr_t sa; @@ -747,6 +749,7 @@ void handle_new_meta_connection(void *data, int flags) { accept a new UNIX socket connection */ void handle_new_unix_connection(void *data, int flags) { + (void)flags; io_t *io = data; connection_t *c; sockaddr_t sa; diff --git a/src/netutl.c b/src/netutl.c index 4e58911c..2916e9ae 100644 --- a/src/netutl.c +++ b/src/netutl.c @@ -54,7 +54,7 @@ struct addrinfo *str2addrinfo(const char *address, const char *service, int sock sockaddr_t str2sockaddr(const char *address, const char *port) { struct addrinfo *ai, hint = {0}; - sockaddr_t result = {{0}}; + sockaddr_t result = {0}; int err; hint.ai_family = AF_UNSPEC; diff --git a/src/node.c b/src/node.c index 4ec5d353..b5e033c1 100644 --- a/src/node.c +++ b/src/node.c @@ -152,7 +152,7 @@ void node_del(node_t *n) { } node_t *lookup_node(char *name) { - node_t n = {NULL}; + node_t n = {0}; n.name = name; @@ -213,14 +213,14 @@ bool dump_nodes(connection_t *c) { id[sizeof(id) - 1] = 0; send_request(c, "%d %d %s %s %s %d %d %d %d %x %x %s %s %d %d %d %d %ld %d %"PRIu64" %"PRIu64" %"PRIu64" %"PRIu64, CONTROL, REQ_DUMP_NODES, - n->name, id, n->hostname ? : "unknown port unknown", + n->name, id, n->hostname ? n->hostname : "unknown port unknown", #ifdef DISABLE_LEGACY 0, 0, 0, #else cipher_get_nid(n->outcipher), digest_get_nid(n->outdigest), (int)digest_length(n->outdigest), #endif n->outcompression, n->options, bitfield_to_int(&n->status, sizeof(n->status)), - n->nexthop ? n->nexthop->name : "-", n->via ? n->via->name ? : "-" : "-", n->distance, + n->nexthop ? n->nexthop->name : "-", n->via && n->via->name ? n->via->name : "-", n->distance, n->mtu, n->minmtu, n->maxmtu, (long)n->last_state_change, n->udp_ping_rtt, n->in_packets, n->in_bytes, n->out_packets, n->out_bytes); } diff --git a/src/openssl/crypto.c b/src/openssl/crypto.c index 6894d876..e594e73a 100644 --- a/src/openssl/crypto.c +++ b/src/openssl/crypto.c @@ -46,7 +46,9 @@ static void random_exit(void) { close(random_fd); } -void randomize(void *out, size_t outlen) { +void randomize(void *vout, size_t outlen) { + char *out = vout; + while(outlen) { size_t len = read(random_fd, out, outlen); diff --git a/src/openssl/prf.c b/src/openssl/prf.c index d87c5c68..37af2ef5 100644 --- a/src/openssl/prf.c +++ b/src/openssl/prf.c @@ -29,7 +29,7 @@ We use SHA512 instead of MD5 and SHA1. */ -static bool prf_xor(int nid, const char *secret, size_t secretlen, char *seed, size_t seedlen, char *out, ssize_t outlen) { +static bool prf_xor(int nid, const char *secret, size_t secretlen, char *seed, size_t seedlen, char *out, size_t outlen) { digest_t *digest = digest_open_by_nid(nid, -1); if(!digest) { @@ -67,7 +67,7 @@ static bool prf_xor(int nid, const char *secret, size_t secretlen, char *seed, s } /* XOR the results of the outer HMAC into the out buffer */ - for(int i = 0; i < len && i < outlen; i++) { + for(size_t i = 0; i < len && i < outlen; i++) { *out++ ^= hash[i]; } diff --git a/src/openssl/rsa.c b/src/openssl/rsa.c index e1ae4f61..0e811722 100644 --- a/src/openssl/rsa.c +++ b/src/openssl/rsa.c @@ -46,7 +46,7 @@ rsa_t *rsa_set_hex_public_key(char *n, char *e) { BIGNUM *bn_n = NULL; BIGNUM *bn_e = NULL; - if(BN_hex2bn(&bn_n, n) != strlen(n) || BN_hex2bn(&bn_e, e) != strlen(e)) { + if((size_t)BN_hex2bn(&bn_n, n) != strlen(n) || (size_t)BN_hex2bn(&bn_e, e) != strlen(e)) { BN_free(bn_e); BN_free(bn_n); return false; @@ -68,7 +68,7 @@ rsa_t *rsa_set_hex_private_key(char *n, char *e, char *d) { BIGNUM *bn_e = NULL; BIGNUM *bn_d = NULL; - if(BN_hex2bn(&bn_n, n) != strlen(n) || BN_hex2bn(&bn_e, e) != strlen(e) || BN_hex2bn(&bn_d, d) != strlen(d)) { + if((size_t)BN_hex2bn(&bn_n, n) != strlen(n) || (size_t)BN_hex2bn(&bn_e, e) != strlen(e) || (size_t)BN_hex2bn(&bn_d, d) != strlen(d)) { BN_free(bn_d); BN_free(bn_e); BN_free(bn_n); @@ -118,7 +118,7 @@ size_t rsa_size(rsa_t *rsa) { } bool rsa_public_encrypt(rsa_t *rsa, void *in, size_t len, void *out) { - if(RSA_public_encrypt(len, in, out, rsa, RSA_NO_PADDING) == len) { + if((size_t)RSA_public_encrypt(len, in, out, rsa, RSA_NO_PADDING) == len) { return true; } @@ -127,7 +127,7 @@ bool rsa_public_encrypt(rsa_t *rsa, void *in, size_t len, void *out) { } bool rsa_private_decrypt(rsa_t *rsa, void *in, size_t len, void *out) { - if(RSA_private_decrypt(len, in, out, rsa, RSA_NO_PADDING) == len) { + if((size_t)RSA_private_decrypt(len, in, out, rsa, RSA_NO_PADDING) == len) { return true; } diff --git a/src/openssl/rsagen.c b/src/openssl/rsagen.c index c8546971..79127f68 100644 --- a/src/openssl/rsagen.c +++ b/src/openssl/rsagen.c @@ -32,6 +32,8 @@ typedef RSA rsa_t; /* 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, "."); diff --git a/src/protocol.c b/src/protocol.c index c7dd8fb4..1ca24e57 100644 --- a/src/protocol.c +++ b/src/protocol.c @@ -76,7 +76,7 @@ bool send_request(connection_t *c, const char *format, ...) { request[sizeof(request) - 1] = 0; va_end(args); - if(len < 0 || len > sizeof(request) - 1) { + if(len < 0 || (size_t)len > sizeof(request) - 1) { logger(DEBUG_ALWAYS, LOG_ERR, "Output buffer overflow while sending request to %s (%s)", c->name, c->hostname); return false; @@ -175,6 +175,7 @@ static void free_past_request(past_request_t *r) { static timeout_t past_request_timeout; static void age_past_requests(void *data) { + (void)data; int left = 0, deleted = 0; for splay_each(past_request_t, p, past_request_tree) { @@ -196,7 +197,7 @@ static void age_past_requests(void *data) { } bool seen_request(const char *request) { - past_request_t *new, p = {NULL}; + past_request_t *new, p = {0}; p.request = request; diff --git a/src/protocol_auth.c b/src/protocol_auth.c index 9d61ab8f..eb1754c1 100644 --- a/src/protocol_auth.c +++ b/src/protocol_auth.c @@ -176,6 +176,8 @@ bool send_id(connection_t *c) { } static bool finalize_invitation(connection_t *c, const char *data, uint16_t len) { + (void)len; + if(strchr(data, '\n')) { logger(DEBUG_ALWAYS, LOG_ERR, "Received invalid key from invited node %s (%s)!\n", c->name, c->hostname); return false; @@ -606,7 +608,7 @@ bool metakey_h(connection_t *c, const char *request) { /* Convert the challenge from hexadecimal back to binary */ - int inlen = hex2bin(hexkey, enckey, sizeof(enckey)); + size_t inlen = hex2bin(hexkey, enckey, sizeof(enckey)); /* Check if the length of the meta key is all right */ @@ -762,7 +764,7 @@ bool chal_reply_h(connection_t *c, const char *request) { /* Convert the hash to binary format */ - int inlen = hex2bin(hishash, hishash, sizeof(hishash)); + size_t inlen = hex2bin(hishash, hishash, sizeof(hishash)); /* Check if the length of the hash is all right */ diff --git a/src/protocol_edge.c b/src/protocol_edge.c index 9fd301f2..d650c36f 100644 --- a/src/protocol_edge.c +++ b/src/protocol_edge.c @@ -70,7 +70,7 @@ bool add_edge_h(connection_t *c, const char *request) { char to_port[MAX_STRING_SIZE]; char address_local[MAX_STRING_SIZE]; char port_local[MAX_STRING_SIZE]; - sockaddr_t address, local_address = {{0}}; + sockaddr_t address, local_address = {0}; uint32_t options; int weight; diff --git a/src/protocol_key.c b/src/protocol_key.c index a0a18462..58a3bd20 100644 --- a/src/protocol_key.c +++ b/src/protocol_key.c @@ -100,10 +100,13 @@ static bool send_sptps_data_myself(void *handle, uint8_t type, const void *data, } static bool send_initial_sptps_data(void *handle, uint8_t type, const void *data, size_t len) { + (void)type; node_t *to = handle; to->sptps.send_data = send_sptps_data_myself; char buf[len * 4 / 3 + 5]; + b64encode(data, buf, len); + return send_request(to->nexthop->connection, "%d %s %s %d %s", REQ_KEY, myself->name, to->name, REQ_KEY, buf); } @@ -131,6 +134,8 @@ bool send_req_key(node_t *to) { /* REQ_KEY is overloaded to allow arbitrary requests to be routed between two nodes. */ static bool req_key_ext_h(connection_t *c, const char *request, node_t *from, node_t *to, int reqno) { + (void)c; + /* If this is a SPTPS packet, see if sending UDP info helps. Note that we only do this if we're the destination or the static relay; otherwise every hop would initiate its own UDP info message, resulting in elevated chatter. */ @@ -227,7 +232,7 @@ static bool req_key_ext_h(connection_t *c, const char *request, node_t *from, no } char buf[MAX_STRING_SIZE]; - int len; + size_t len; if(sscanf(request, "%*d %*s %*s %*d " MAX_STRING, buf) != 1 || !(len = b64decode(buf, buf, strlen(buf)))) { logger(DEBUG_ALWAYS, LOG_ERR, "Got bad %s from %s (%s): %s", "REQ_SPTPS_START", from->name, from->hostname, "invalid SPTPS data"); @@ -466,7 +471,7 @@ bool ans_key_h(connection_t *c, const char *request) { if(from->status.sptps) { char buf[strlen(key)]; - int len = b64decode(key, buf, strlen(key)); + size_t len = b64decode(key, buf, strlen(key)); if(!len || !sptps_receive_data(&from->sptps, buf, len)) { /* Uh-oh. It might be that the tunnel is stuck in some corrupted state, @@ -519,14 +524,14 @@ bool ans_key_h(connection_t *c, const char *request) { from->outdigest = NULL; } - if(maclength != digest_length(from->outdigest)) { + if((size_t)maclength != digest_length(from->outdigest)) { logger(DEBUG_ALWAYS, LOG_ERR, "Node %s (%s) uses bogus MAC length!", from->name, from->hostname); return false; } /* Process key */ - int keylen = hex2bin(key, key, sizeof(key)); + size_t keylen = hex2bin(key, key, sizeof(key)); if(keylen != (from->outcipher ? cipher_keylength(from->outcipher) : 1)) { logger(DEBUG_ALWAYS, LOG_ERR, "Node %s (%s) uses wrong keylength!", from->name, from->hostname); diff --git a/src/protocol_misc.c b/src/protocol_misc.c index d808d73f..a4fcd6f7 100644 --- a/src/protocol_misc.c +++ b/src/protocol_misc.c @@ -44,6 +44,8 @@ bool send_termreq(connection_t *c) { } bool termreq_h(connection_t *c, const char *request) { + (void)c; + (void)request; return false; } @@ -55,6 +57,7 @@ bool send_ping(connection_t *c) { } bool ping_h(connection_t *c, const char *request) { + (void)request; return send_pong(c); } @@ -63,6 +66,7 @@ bool send_pong(connection_t *c) { } bool pong_h(connection_t *c, const char *request) { + (void)request; c->status.pinged = false; /* Successful connection, reset timeout if this is an outgoing connection. */ diff --git a/src/protocol_subnet.c b/src/protocol_subnet.c index 3e82e473..53afb8a4 100644 --- a/src/protocol_subnet.c +++ b/src/protocol_subnet.c @@ -46,7 +46,7 @@ bool add_subnet_h(connection_t *c, const char *request) { char subnetstr[MAX_STRING_SIZE]; char name[MAX_STRING_SIZE]; node_t *owner; - subnet_t s = {NULL}, *new, *old; + subnet_t s = {0}, *new, *old; if(sscanf(request, "%*d %*x " MAX_STRING " " MAX_STRING, name, subnetstr) != 2) { logger(DEBUG_ALWAYS, LOG_ERR, "Got bad %s from %s (%s)", "ADD_SUBNET", c->name, @@ -162,7 +162,7 @@ bool del_subnet_h(connection_t *c, const char *request) { char subnetstr[MAX_STRING_SIZE]; char name[MAX_STRING_SIZE]; node_t *owner; - subnet_t s = {NULL}, *find; + subnet_t s = {0}, *find; if(sscanf(request, "%*d %*x " MAX_STRING " " MAX_STRING, name, subnetstr) != 2) { logger(DEBUG_ALWAYS, LOG_ERR, "Got bad %s from %s (%s)", "DEL_SUBNET", c->name, diff --git a/src/route.c b/src/route.c index 4d712795..3beb2f41 100644 --- a/src/route.c +++ b/src/route.c @@ -495,6 +495,7 @@ static void clamp_mss(const node_t *source, const node_t *via, vpn_packet_t *pac } static void age_subnets(void *data) { + (void)data; bool left = false; for splay_each(subnet_t, s, myself->subnet_tree) { diff --git a/src/splay_tree.c b/src/splay_tree.c index ee855192..4d973732 100644 --- a/src/splay_tree.c +++ b/src/splay_tree.c @@ -25,7 +25,7 @@ /* Splay operation */ static splay_node_t *splay_top_down(splay_tree_t *tree, const void *data, int *result) { - splay_node_t left = {NULL}, right = {NULL}; + splay_node_t left = {0}, right = {0}; splay_node_t *leftbottom = &left, *rightbottom = &right, *child, *grandchild; splay_node_t *root = tree->root; int c; diff --git a/src/sptps.c b/src/sptps.c index 82e913eb..eeaf833e 100644 --- a/src/sptps.c +++ b/src/sptps.c @@ -51,9 +51,16 @@ unsigned int sptps_replaywin = 16; */ void sptps_log_quiet(sptps_t *s, int s_errno, const char *format, va_list ap) { + (void)s; + (void)s_errno; + (void)format; + (void)ap; } void sptps_log_stderr(sptps_t *s, int s_errno, const char *format, va_list ap) { + (void)s; + (void)s_errno; + vfprintf(stderr, format, ap); fputc('\n', stderr); } @@ -62,6 +69,9 @@ void (*sptps_log)(sptps_t *s, int s_errno, const char *format, va_list ap) = spt // Log an error message. static bool error(sptps_t *s, int s_errno, const char *format, ...) { + (void)s; + (void)s_errno; + if(format) { va_list ap; va_start(ap, format); @@ -244,6 +254,8 @@ static bool send_ack(sptps_t *s) { // Receive an ACKnowledgement record. static bool receive_ack(sptps_t *s, const char *data, uint16_t len) { + (void)data; + if(len) { return error(s, EIO, "Invalid ACK record length"); } @@ -381,6 +393,7 @@ static bool receive_handshake(sptps_t *s, const char *data, uint16_t len) { return false; } + // Fall through case SPTPS_KEX: // We have sent our KEX request, we expect our peer to sent one as well. @@ -466,7 +479,7 @@ static bool sptps_check_seqno(sptps_t *s, uint32_t seqno, bool update_state) { } } else if(update_state) { // We missed some packets. Mark them in the bitmap as being late. - for(int i = s->inseqno; i < seqno; i++) { + for(uint32_t i = s->inseqno; i < seqno; i++) { s->late[(i / 8) % s->replaywin] |= 1 << i % 8; } } @@ -495,11 +508,12 @@ static bool sptps_check_seqno(sptps_t *s, uint32_t seqno, bool update_state) { } // Check datagram for valid HMAC -bool sptps_verify_datagram(sptps_t *s, const void *data, size_t len) { +bool sptps_verify_datagram(sptps_t *s, const void *vdata, size_t len) { if(!s->instate || len < 21) { return error(s, EIO, "Received short packet"); } + const char *data = vdata; uint32_t seqno; memcpy(&seqno, data, 4); seqno = ntohl(seqno); @@ -584,7 +598,8 @@ static bool sptps_receive_data_datagram(sptps_t *s, const char *data, size_t len } // Receive incoming data. Check if it contains a complete record, if so, handle it. -size_t sptps_receive_data(sptps_t *s, const void *data, size_t len) { +size_t sptps_receive_data(sptps_t *s, const void *vdata, size_t len) { + const char *data = vdata; size_t total_read = 0; if(!s->state) { diff --git a/src/sptps_keypair.c b/src/sptps_keypair.c index 1bf2da01..51a94eeb 100644 --- a/src/sptps_keypair.c +++ b/src/sptps_keypair.c @@ -28,10 +28,14 @@ static char *program_name; void logger(int level, int priority, const char *format, ...) { + (void)level; + (void)priority; va_list ap; + va_start(ap, format); vfprintf(stderr, format, ap); va_end(ap); + fputc('\n', stderr); } diff --git a/src/sptps_test.c b/src/sptps_test.c index 0f75c242..4ff701ef 100644 --- a/src/sptps_test.c +++ b/src/sptps_test.c @@ -32,12 +32,20 @@ // Symbols necessary to link with logger.o bool send_request(void *c, const char *msg, ...) { + (void)c; + (void)msg; return false; } + struct list_t *connection_list = NULL; + bool send_meta(void *c, const char *msg, int len) { + (void)c; + (void)msg; + (void)len; return false; } + char *logfilename = NULL; bool do_detach = false; struct timeval now; @@ -51,6 +59,7 @@ static int out = 1; static int addressfamily = AF_UNSPEC; static bool send_data(void *handle, uint8_t type, const void *data, size_t len) { + (void)type; char hex[len * 2 + 1]; bin2hex(data, hex, len); @@ -60,7 +69,7 @@ static bool send_data(void *handle, uint8_t type, const void *data, size_t len) const int *sock = handle; - if(send(*sock, data, len, 0) != len) { + if((size_t)send(*sock, data, len, 0) != len) { return false; } @@ -68,6 +77,7 @@ static bool send_data(void *handle, uint8_t type, const void *data, size_t len) } static bool receive_record(void *handle, uint8_t type, const void *data, uint16_t len) { + (void)handle; if(verbose) { fprintf(stderr, "Received type %d record of %u bytes:\n", type, len); } @@ -404,7 +414,7 @@ int main(int argc, char *argv[]) { if(len > 1) { sptps_send_record(&s, 0, buf, len); } - } else if(!sptps_send_record(&s, buf[0] == '!' ? 1 : 0, buf, (len == 1 && buf[0] == '\n') ? 0 : buf[0] == '*' ? sizeof(buf) : len)) { + } else if(!sptps_send_record(&s, buf[0] == '!' ? 1 : 0, buf, (len == 1 && buf[0] == '\n') ? 0 : buf[0] == '*' ? sizeof(buf) : (size_t)len)) { return 1; } } diff --git a/src/subnet_parse.c b/src/subnet_parse.c index 88513f68..d5b84eb6 100644 --- a/src/subnet_parse.c +++ b/src/subnet_parse.c @@ -371,7 +371,7 @@ bool str2net(subnet_t *subnet, const char *subnetstr) { bool net2str(char *netstr, int len, const subnet_t *subnet) { if(!netstr || !subnet) { - logger(DEBUG_ALWAYS, LOG_ERR, "net2str() was called with netstr=%p, subnet=%p!", netstr, subnet); + logger(DEBUG_ALWAYS, LOG_ERR, "net2str() was called with netstr=%p, subnet=%p!", (void *)netstr, (void *)subnet); return false; } diff --git a/src/tincctl.c b/src/tincctl.c index 4f6660a9..93c5b320 100644 --- a/src/tincctl.c +++ b/src/tincctl.c @@ -388,7 +388,7 @@ ask_filename: /* The directory is a relative path or a filename. */ getcwd(directory, sizeof(directory)); - if(snprintf(buf2, sizeof(buf2), "%s" SLASH "%s", directory, filename) >= sizeof(buf2)) { + if((size_t)snprintf(buf2, sizeof(buf2), "%s" SLASH "%s", directory, filename) >= sizeof(buf2)) { fprintf(stderr, "Filename too long: %s" SLASH "%s\n", directory, filename); if(ask && tty) { @@ -577,7 +577,7 @@ bool recvline(int fd, char *line, size_t len) { blen += result; } - if(newline - buffer >= len) { + if((size_t)(newline - buffer) >= len) { return false; } @@ -591,11 +591,7 @@ bool recvline(int fd, char *line, size_t len) { return true; } -bool recvdata(int fd, char *data, size_t len) { - if(len == -1) { - len = blen; - } - +static bool recvdata(int fd, char *data, size_t len) { while(blen < len) { int result = recv(fd, buffer + blen, sizeof(buffer) - blen, 0); @@ -618,7 +614,7 @@ bool recvdata(int fd, char *data, size_t len) { bool sendline(int fd, char *format, ...) { static char buffer[4096]; char *p = buffer; - int blen = 0; + int blen; va_list ap; va_start(ap, format); @@ -626,7 +622,7 @@ bool sendline(int fd, char *format, ...) { buffer[sizeof(buffer) - 1] = 0; va_end(ap); - if(blen < 1 || blen >= sizeof(buffer)) { + if(blen < 1 || (size_t)blen >= sizeof(buffer)) { return false; } @@ -649,7 +645,7 @@ bool sendline(int fd, char *format, ...) { return true; } -static void pcap(int fd, FILE *out, int snaplen) { +static void pcap(int fd, FILE *out, uint32_t snaplen) { sendline(fd, "%d %d %d", CONTROL, REQ_PCAP, snaplen); char data[9018]; @@ -665,7 +661,7 @@ static void pcap(int fd, FILE *out, int snaplen) { 0xa1b2c3d4, 2, 4, 0, 0, - snaplen ? : sizeof(data), + snaplen ? snaplen : sizeof(data), 1, }; @@ -688,7 +684,7 @@ static void pcap(int fd, FILE *out, int snaplen) { int n = sscanf(line, "%d %d %d", &code, &req, &len); gettimeofday(&tv, NULL); - if(n != 3 || code != CONTROL || req != REQ_PCAP || len < 0 || len > sizeof(data)) { + if(n != 3 || code != CONTROL || req != REQ_PCAP || len < 0 || (size_t)len > sizeof(data)) { break; } @@ -715,7 +711,7 @@ static void logcontrol(int fd, FILE *out, int level) { int code, req, len; int n = sscanf(line, "%d %d %d", &code, &req, &len); - if(n != 3 || code != CONTROL || req != REQ_LOG || len < 0 || len > sizeof(data)) { + if(n != 3 || code != CONTROL || req != REQ_LOG || len < 0 || (size_t)len > sizeof(data)) { break; } @@ -1080,6 +1076,8 @@ static int cmd_start(int argc, char *argv[]) { } static int cmd_stop(int argc, char *argv[]) { + (void)argv; + if(argc > 1) { fprintf(stderr, "Too many arguments!\n"); return 1; @@ -1128,6 +1126,8 @@ static int cmd_restart(int argc, char *argv[]) { } static int cmd_reload(int argc, char *argv[]) { + (void)argv; + if(argc > 1) { fprintf(stderr, "Too many arguments!\n"); return 1; @@ -1176,7 +1176,7 @@ static int dump_invitations(void) { char fname[PATH_MAX]; - if(snprintf(fname, sizeof(fname), "%s" SLASH "%s", dname, ent->d_name) >= sizeof(fname)) { + if((size_t)snprintf(fname, sizeof(fname), "%s" SLASH "%s", dname, ent->d_name) >= sizeof(fname)) { fprintf(stderr, "Filename too long: %s" SLASH "%s\n", dname, ent->d_name); continue; } @@ -1421,6 +1421,8 @@ static int cmd_dump(int argc, char *argv[]) { } static int cmd_purge(int argc, char *argv[]) { + (void)argv; + if(argc > 1) { fprintf(stderr, "Too many arguments!\n"); return 1; @@ -1465,6 +1467,8 @@ static int cmd_debug(int argc, char *argv[]) { } static int cmd_retry(int argc, char *argv[]) { + (void)argv; + if(argc > 1) { fprintf(stderr, "Too many arguments!\n"); return 1; @@ -1535,6 +1539,8 @@ static int cmd_disconnect(int argc, char *argv[]) { } static int cmd_top(int argc, char *argv[]) { + (void)argv; + if(argc > 1) { fprintf(stderr, "Too many arguments!\n"); return 1; @@ -1570,6 +1576,8 @@ static int cmd_pcap(int argc, char *argv[]) { #ifdef SIGINT static void sigint_handler(int sig) { + (void)sig; + fprintf(stderr, "\n"); shutdown(fd, SHUT_RDWR); } @@ -1601,6 +1609,8 @@ static int cmd_log(int argc, char *argv[]) { } static int cmd_pid(int argc, char *argv[]) { + (void)argv; + if(argc > 1) { fprintf(stderr, "Too many arguments!\n"); return 1; @@ -1949,7 +1959,7 @@ static int cmd_config(int argc, char *argv[]) { FILE *tf = NULL; if(action >= -1) { - if(snprintf(tmpfile, sizeof(tmpfile), "%s.config.tmp", filename) >= sizeof(tmpfile)) { + if((size_t)snprintf(tmpfile, sizeof(tmpfile), "%s.config.tmp", filename) >= sizeof(tmpfile)) { fprintf(stderr, "Filename too long: %s.config.tmp\n", filename); return 1; } @@ -2336,6 +2346,8 @@ static int cmd_generate_rsa_keys(int argc, char *argv[]) { #endif static int cmd_generate_ed25519_keys(int argc, char *argv[]) { + (void)argv; + if(argc > 1) { fprintf(stderr, "Too many arguments!\n"); return 1; @@ -2349,11 +2361,16 @@ static int cmd_generate_ed25519_keys(int argc, char *argv[]) { } static int cmd_help(int argc, char *argv[]) { + (void)argc; + (void)argv; + usage(false); return 0; } static int cmd_version(int argc, char *argv[]) { + (void)argv; + if(argc > 1) { fprintf(stderr, "Too many arguments!\n"); return 1; @@ -2422,7 +2439,13 @@ static int cmd_edit(int argc, char *argv[]) { char *command; #ifndef HAVE_MINGW - xasprintf(&command, "\"%s\" \"%s\"", getenv("VISUAL") ? : getenv("EDITOR") ? : "vi", filename); + const char *editor = getenv("VISUAL"); + if (!editor) + editor = getenv("EDITOR"); + if (!editor) + editor = "vi"; + + xasprintf(&command, "\"%s\" \"%s\"", editor, filename); #else xasprintf(&command, "edit \"%s\"", filename); #endif @@ -2471,6 +2494,8 @@ static int export(const char *name, FILE *out) { } static int cmd_export(int argc, char *argv[]) { + (void)argv; + if(argc > 1) { fprintf(stderr, "Too many arguments!\n"); return 1; @@ -2493,6 +2518,8 @@ static int cmd_export(int argc, char *argv[]) { } static int cmd_export_all(int argc, char *argv[]) { + (void)argv; + if(argc > 1) { fprintf(stderr, "Too many arguments!\n"); return 1; @@ -2533,6 +2560,8 @@ static int cmd_export_all(int argc, char *argv[]) { } static int cmd_import(int argc, char *argv[]) { + (void)argv; + if(argc > 1) { fprintf(stderr, "Too many arguments!\n"); return 1; @@ -2560,7 +2589,7 @@ static int cmd_import(int argc, char *argv[]) { fclose(out); } - if(snprintf(filename, sizeof(filename), "%s" SLASH "%s", hosts_dir, name) >= sizeof(filename)) { + if((size_t)snprintf(filename, sizeof(filename), "%s" SLASH "%s", hosts_dir, name) >= sizeof(filename)) { fprintf(stderr, "Filename too long: %s" SLASH "%s\n", hosts_dir, name); return 1; } @@ -2612,11 +2641,11 @@ static int cmd_import(int argc, char *argv[]) { } static int cmd_exchange(int argc, char *argv[]) { - return cmd_export(argc, argv) ? : cmd_import(argc, argv); + return cmd_export(argc, argv) ? 1 : cmd_import(argc, argv); } static int cmd_exchange_all(int argc, char *argv[]) { - return cmd_export_all(argc, argv) ? : cmd_import(argc, argv); + return cmd_export_all(argc, argv) ? 1 : cmd_import(argc, argv); } static int switch_network(char *name) { @@ -2694,6 +2723,8 @@ static int cmd_network(int argc, char *argv[]) { } static int cmd_fsck(int argc, char *argv[]) { + (void)argv; + if(argc > 1) { fprintf(stderr, "Too many arguments!\n"); return 1; @@ -2962,48 +2993,48 @@ static const struct { int (*function)(int argc, char *argv[]); bool hidden; } commands[] = { - {"start", cmd_start}, - {"stop", cmd_stop}, - {"restart", cmd_restart}, - {"reload", cmd_reload}, - {"dump", cmd_dump}, - {"list", cmd_dump}, - {"purge", cmd_purge}, - {"debug", cmd_debug}, - {"retry", cmd_retry}, - {"connect", cmd_connect}, - {"disconnect", cmd_disconnect}, - {"top", cmd_top}, - {"pcap", cmd_pcap}, - {"log", cmd_log}, - {"pid", cmd_pid}, + {"start", cmd_start, false}, + {"stop", cmd_stop, false}, + {"restart", cmd_restart, false}, + {"reload", cmd_reload, false}, + {"dump", cmd_dump, false}, + {"list", cmd_dump, false}, + {"purge", cmd_purge, false}, + {"debug", cmd_debug, false}, + {"retry", cmd_retry, false}, + {"connect", cmd_connect, false}, + {"disconnect", cmd_disconnect, false}, + {"top", cmd_top, false}, + {"pcap", cmd_pcap, false}, + {"log", cmd_log, false}, + {"pid", cmd_pid, false}, {"config", cmd_config, true}, - {"add", cmd_config}, - {"del", cmd_config}, - {"get", cmd_config}, - {"set", cmd_config}, - {"init", cmd_init}, - {"generate-keys", cmd_generate_keys}, + {"add", cmd_config, false}, + {"del", cmd_config, false}, + {"get", cmd_config, false}, + {"set", cmd_config, false}, + {"init", cmd_init, false}, + {"generate-keys", cmd_generate_keys, false}, #ifndef DISABLE_LEGACY - {"generate-rsa-keys", cmd_generate_rsa_keys}, + {"generate-rsa-keys", cmd_generate_rsa_keys, false}, #endif - {"generate-ed25519-keys", cmd_generate_ed25519_keys}, - {"help", cmd_help}, - {"version", cmd_version}, - {"info", cmd_info}, - {"edit", cmd_edit}, - {"export", cmd_export}, - {"export-all", cmd_export_all}, - {"import", cmd_import}, - {"exchange", cmd_exchange}, - {"exchange-all", cmd_exchange_all}, - {"invite", cmd_invite}, - {"join", cmd_join}, - {"network", cmd_network}, - {"fsck", cmd_fsck}, - {"sign", cmd_sign}, - {"verify", cmd_verify}, - {NULL, NULL}, + {"generate-ed25519-keys", cmd_generate_ed25519_keys, false}, + {"help", cmd_help, false}, + {"version", cmd_version, false}, + {"info", cmd_info, false}, + {"edit", cmd_edit, false}, + {"export", cmd_export, false}, + {"export-all", cmd_export_all, false}, + {"import", cmd_import, false}, + {"exchange", cmd_exchange, false}, + {"exchange-all", cmd_exchange_all, false}, + {"invite", cmd_invite, false}, + {"join", cmd_join, false}, + {"network", cmd_network, false}, + {"fsck", cmd_fsck, false}, + {"sign", cmd_sign, false}, + {"verify", cmd_verify, false}, + {NULL, NULL, false}, }; #ifdef HAVE_READLINE @@ -3121,10 +3152,13 @@ static char *complete_info(const char *text, int state) { } static char *complete_nothing(const char *text, int state) { + (void)text; + (void)state; return NULL; } static char **completion(const char *text, int start, int end) { + (void)end; char **matches = NULL; if(!start) { diff --git a/src/top.c b/src/top.c index 792f2240..ab146195 100644 --- a/src/top.c +++ b/src/top.c @@ -239,7 +239,7 @@ static int sortfunc(const void *a, const void *b) { static void redraw(void) { erase(); - mvprintw(0, 0, "Tinc %-16s Nodes: %4d Sort: %-10s %s", netname ? : "", node_list.count, sortname[sortmode], cumulative ? "Cumulative" : "Current"); + mvprintw(0, 0, "Tinc %-16s Nodes: %4d Sort: %-10s %s", netname ? netname : "", node_list.count, sortname[sortmode], cumulative ? "Cumulative" : "Current"); attrset(A_REVERSE); mvprintw(2, 0, "Node IN %s IN %s OUT %s OUT %s", punit, bunit, punit, bunit); chgat(-1, A_REVERSE, 0, NULL); diff --git a/src/upnp.c b/src/upnp.c index 5149714d..5e41d1b6 100644 --- a/src/upnp.c +++ b/src/upnp.c @@ -148,6 +148,8 @@ static void upnp_refresh() { } static void *upnp_thread(void *data) { + (void)data; + while(true) { time_t start = time(NULL); upnp_refresh(); diff --git a/src/utils.c b/src/utils.c index 364ae430..857d47ed 100644 --- a/src/utils.c +++ b/src/utils.c @@ -53,9 +53,9 @@ static int charhex2bin(char c) { } } -int hex2bin(const char *src, void *vdst, int length) { +size_t hex2bin(const char *src, void *vdst, size_t length) { char *dst = vdst; - int i; + size_t i; for(i = 0; i < length && isxdigit(src[i * 2]) && isxdigit(src[i * 2 + 1]); i++) { dst[i] = charhex2bin(src[i * 2]) * 16 + charhex2bin(src[i * 2 + 1]); @@ -64,10 +64,10 @@ int hex2bin(const char *src, void *vdst, int length) { return i; } -int bin2hex(const void *vsrc, char *dst, int length) { +size_t bin2hex(const void *vsrc, char *dst, size_t length) { const char *src = vsrc; - for(int i = length - 1; i >= 0; i--) { + for(size_t i = length; i-- > 0;) { dst[i * 2 + 1] = hexadecimals[(unsigned char) src[i] & 15]; dst[i * 2] = hexadecimals[(unsigned char) src[i] >> 4]; } @@ -76,8 +76,8 @@ int bin2hex(const void *vsrc, char *dst, int length) { return length * 2; } -int b64decode(const char *src, void *dst, int length) { - int i; +size_t b64decode(const char *src, void *dst, size_t length) { + size_t i; uint32_t triplet = 0; unsigned char *udst = (unsigned char *)dst; @@ -116,11 +116,11 @@ int b64decode(const char *src, void *dst, int length) { } } -static int b64encode_internal(const void *src, char *dst, int length, const char *alphabet) { +static size_t b64encode_internal(const void *src, char *dst, size_t length, const char *alphabet) { uint32_t triplet; const unsigned char *usrc = (unsigned char *)src; - int si = length / 3 * 3; - int di = length / 3 * 4; + size_t si = length / 3 * 3; + size_t di = length / 3 * 4; switch(length % 3) { case 2: @@ -165,11 +165,11 @@ static int b64encode_internal(const void *src, char *dst, int length, const char return length; } -int b64encode(const void *src, char *dst, int length) { +size_t b64encode(const void *src, char *dst, size_t length) { return b64encode_internal(src, dst, length, base64_original); } -int b64encode_urlsafe(const void *src, char *dst, int length) { +size_t b64encode_urlsafe(const void *src, char *dst, size_t length) { return b64encode_internal(src, dst, length, base64_urlsafe); } diff --git a/src/utils.h b/src/utils.h index a0f64bb0..42851501 100644 --- a/src/utils.h +++ b/src/utils.h @@ -21,12 +21,12 @@ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ -extern int hex2bin(const char *src, void *dst, int length); -extern int bin2hex(const void *src, char *dst, int length); +extern size_t hex2bin(const char *src, void *dst, size_t length); +extern size_t bin2hex(const void *src, char *dst, size_t length); -extern int b64encode(const void *src, char *dst, int length); -extern int b64encode_urlsafe(const void *src, char *dst, int length); -extern int b64decode(const char *src, void *dst, int length); +extern size_t b64encode(const void *src, char *dst, size_t length); +extern size_t b64encode_urlsafe(const void *src, char *dst, size_t length); +extern size_t b64decode(const char *src, void *dst, size_t length); #ifdef HAVE_MINGW extern const char *winerror(int); -- 2.20.1