From: Guus Sliepen Date: Sat, 7 Oct 2017 15:47:19 +0000 (+0200) Subject: Convert sizeof foo to sizeof(foo). X-Git-Tag: release-1.1pre16~64 X-Git-Url: https://git.tinc-vpn.org/git/browse?a=commitdiff_plain;h=3a316823b971396a428f020f401b9fe41252d98d;p=tinc Convert sizeof foo to sizeof(foo). While technically sizeof is an operator and doesn't need the parentheses around expressions it operates on, except if they are type names, code formatters don't seem to handle this very well. --- diff --git a/src/autoconnect.c b/src/autoconnect.c index 1ea51b5e..e97a33ce 100644 --- a/src/autoconnect.c +++ b/src/autoconnect.c @@ -56,7 +56,7 @@ static void make_new_connection() { if(!found) { logger(DEBUG_CONNECTIONS, LOG_INFO, "Autoconnecting to %s", n->name); - outgoing_t *outgoing = xzalloc(sizeof *outgoing); + outgoing_t *outgoing = xzalloc(sizeof(*outgoing)); outgoing->name = xstrdup(n->name); list_insert_tail(outgoing_list, outgoing); setup_outgoing_connection(outgoing); @@ -90,7 +90,7 @@ static void connect_to_unreachable() { return; logger(DEBUG_CONNECTIONS, LOG_INFO, "Autoconnecting to %s", n->name); - outgoing_t *outgoing = xzalloc(sizeof *outgoing); + outgoing_t *outgoing = xzalloc(sizeof(*outgoing)); outgoing->name = xstrdup(n->name); list_insert_tail(outgoing_list, outgoing); setup_outgoing_connection(outgoing); diff --git a/src/bsd/device.c b/src/bsd/device.c index 4a63e840..ec088a42 100644 --- a/src/bsd/device.c +++ b/src/bsd/device.c @@ -74,7 +74,7 @@ static bool setup_utun(void) { } struct ctl_info info = {}; - strlcpy(info.ctl_name, UTUN_CONTROL_NAME, sizeof info.ctl_name); + strlcpy(info.ctl_name, UTUN_CONTROL_NAME, sizeof(info.ctl_name)); if(ioctl(device_fd, CTLIOCGINFO, &info) == -1) { logger(DEBUG_ALWAYS, LOG_ERR, "ioctl(CTLIOCGINFO) failed: %s", strerror(errno)); @@ -91,7 +91,7 @@ static bool setup_utun(void) { struct sockaddr_ctl sc = { .sc_id = info.ctl_id, - .sc_len = sizeof sc, + .sc_len = sizeof(sc), .sc_family = AF_SYSTEM, .ss_sysaddr = AF_SYS_CONTROL, .sc_unit = unit + 1, @@ -103,7 +103,7 @@ static bool setup_utun(void) { } char name[64] = ""; - socklen_t len = sizeof name; + socklen_t len = sizeof(name); if(getsockopt(device_fd, SYSPROTO_CONTROL, UTUN_OPT_IFNAME, name, &len)) { iface = xstrdup(device); } else { @@ -225,7 +225,7 @@ static bool setup_device(void) { #ifdef TUNSIFHEAD { const int zero = 0; - if(ioctl(device_fd, TUNSIFHEAD, &zero, sizeof zero) == -1) { + if(ioctl(device_fd, TUNSIFHEAD, &zero, sizeof(zero)) == -1) { logger(DEBUG_ALWAYS, LOG_ERR, "System call `%s' failed: %s", "ioctl", strerror(errno)); return false; } @@ -234,7 +234,7 @@ static bool setup_device(void) { #if defined(TUNSIFMODE) && defined(IFF_BROADCAST) && defined(IFF_MULTICAST) { const int mode = IFF_BROADCAST | IFF_MULTICAST; - ioctl(device_fd, TUNSIFMODE, &mode, sizeof mode); + ioctl(device_fd, TUNSIFMODE, &mode, sizeof(mode)); } #endif @@ -244,7 +244,7 @@ static bool setup_device(void) { #ifdef TUNSIFHEAD { const int one = 1; - if(ioctl(device_fd, TUNSIFHEAD, &one, sizeof one) == -1) { + if(ioctl(device_fd, TUNSIFHEAD, &one, sizeof(one)) == -1) { logger(DEBUG_ALWAYS, LOG_ERR, "System call `%s' failed: %s", "ioctl", strerror(errno)); return false; } @@ -253,7 +253,7 @@ static bool setup_device(void) { #if defined(TUNSIFMODE) && defined(IFF_BROADCAST) && defined(IFF_MULTICAST) { const int mode = IFF_BROADCAST | IFF_MULTICAST; - ioctl(device_fd, TUNSIFMODE, &mode, sizeof mode); + ioctl(device_fd, TUNSIFMODE, &mode, sizeof(mode)); } #endif @@ -431,7 +431,7 @@ static bool write_packet(vpn_packet_t *packet) { return false; } - memcpy(DATA(packet) + 10, &type, sizeof type); + memcpy(DATA(packet) + 10, &type, sizeof(type)); if(write(device_fd, DATA(packet) + 10, packet->len - 10) < 0) { logger(DEBUG_ALWAYS, LOG_ERR, "Can't write to %s %s: %s", device_info, device, diff --git a/src/bsd/tunemu.c b/src/bsd/tunemu.c index d2b9f3d9..6d5dd1aa 100644 --- a/src/bsd/tunemu.c +++ b/src/bsd/tunemu.c @@ -87,7 +87,7 @@ static void tun_error(char *format, ...) { va_list vl; va_start(vl, format); - vsnprintf(tunemu_error, sizeof tunemu_error, format, vl); + vsnprintf(tunemu_error, sizeof(tunemu_error), format, vl); va_end(vl); } diff --git a/src/chacha-poly1305/chacha-poly1305.c b/src/chacha-poly1305/chacha-poly1305.c index bd5cb2c4..d4f37237 100644 --- a/src/chacha-poly1305/chacha-poly1305.c +++ b/src/chacha-poly1305/chacha-poly1305.c @@ -13,7 +13,7 @@ struct chacha_poly1305_ctx { chacha_poly1305_ctx_t *chacha_poly1305_init(void) { - chacha_poly1305_ctx_t *ctx = xzalloc(sizeof *ctx); + chacha_poly1305_ctx_t *ctx = xzalloc(sizeof(*ctx)); return ctx; } diff --git a/src/conf.c b/src/conf.c index 7756247b..8a7e525f 100644 --- a/src/conf.c +++ b/src/conf.c @@ -202,9 +202,9 @@ bool get_config_subnet(const config_t *cfg, subnet_t ** result) { /* Teach newbies what subnets are... */ if(((subnet.type == SUBNET_IPV4) - && !maskcheck(&subnet.net.ipv4.address, subnet.net.ipv4.prefixlength, sizeof subnet.net.ipv4.address)) + && !maskcheck(&subnet.net.ipv4.address, subnet.net.ipv4.prefixlength, sizeof(subnet.net.ipv4.address))) || ((subnet.type == SUBNET_IPV6) - && !maskcheck(&subnet.net.ipv6.address, subnet.net.ipv6.prefixlength, sizeof subnet.net.ipv6.address))) { + && !maskcheck(&subnet.net.ipv6.address, subnet.net.ipv6.prefixlength, sizeof(subnet.net.ipv6.address)))) { logger(DEBUG_ALWAYS, LOG_ERR, "Network address and prefix length do not match for configuration variable %s in %s line %d", cfg->variable, cfg->file, cfg->line); return false; @@ -303,7 +303,7 @@ bool read_config_file(splay_tree_t *config_tree, const char *fname) { } for(;;) { - line = readline(fp, buffer, sizeof buffer); + line = readline(fp, buffer, sizeof(buffer)); if(!line) { if(feof(fp)) @@ -373,14 +373,14 @@ bool read_server_config(void) { read_config_options(config_tree, NULL); - snprintf(fname, sizeof fname, "%s" SLASH "tinc.conf", confbase); + snprintf(fname, sizeof(fname), "%s" SLASH "tinc.conf", confbase); errno = 0; x = read_config_file(config_tree, fname); // We will try to read the conf files in the "conf.d" dir if (x) { char dname[PATH_MAX]; - snprintf(dname, sizeof dname, "%s" SLASH "conf.d", confbase); + snprintf(dname, sizeof(dname), "%s" SLASH "conf.d", confbase); DIR *dir = opendir (dname); // If we can find this dir if (dir) { @@ -390,7 +390,7 @@ bool read_server_config(void) { size_t l = strlen(ep->d_name); // And we try to read the ones that end with ".conf" if (l > 5 && !strcmp(".conf", & ep->d_name[ l - 5 ])) { - snprintf(fname, sizeof fname, "%s" SLASH "%s", dname, ep->d_name); + snprintf(fname, sizeof(fname), "%s" SLASH "%s", dname, ep->d_name); x = read_config_file(config_tree, fname); } } @@ -410,7 +410,7 @@ bool read_host_config(splay_tree_t *config_tree, const char *name) { read_config_options(config_tree, name); - snprintf(fname, sizeof fname, "%s" SLASH "hosts" SLASH "%s", confbase, name); + snprintf(fname, sizeof(fname), "%s" SLASH "hosts" SLASH "%s", confbase, name); x = read_config_file(config_tree, fname); return x; @@ -418,7 +418,7 @@ bool read_host_config(splay_tree_t *config_tree, const char *name) { bool append_config_file(const char *name, const char *key, const char *value) { char fname[PATH_MAX]; - snprintf(fname, sizeof fname, "%s" SLASH "hosts" SLASH "%s", confbase, name); + snprintf(fname, sizeof(fname), "%s" SLASH "hosts" SLASH "%s", confbase, name); FILE *fp = fopen(fname, "a"); diff --git a/src/connection.c b/src/connection.c index 0e61132c..5fcecbd1 100644 --- a/src/connection.c +++ b/src/connection.c @@ -98,7 +98,7 @@ bool dump_connections(connection_t *cdump) { send_request(cdump, "%d %d %s %s %x %d %x", CONTROL, REQ_DUMP_CONNECTIONS, c->name, c->hostname, c->options, c->socket, - bitfield_to_int(&c->status, sizeof c->status)); + bitfield_to_int(&c->status, sizeof(c->status))); } return send_request(cdump, "%d %d", CONTROL, REQ_DUMP_CONNECTIONS); diff --git a/src/control.c b/src/control.c index 98eae804..bf8a12b5 100644 --- a/src/control.c +++ b/src/control.c @@ -134,8 +134,8 @@ bool control_h(connection_t *c, const char *request) { } bool init_control(void) { - randomize(controlcookie, sizeof controlcookie / 2); - bin2hex(controlcookie, controlcookie, sizeof controlcookie / 2); + randomize(controlcookie, sizeof(controlcookie) / 2); + bin2hex(controlcookie, controlcookie, sizeof(controlcookie) / 2); mode_t mask = umask(0); umask(mask | 077); @@ -151,7 +151,7 @@ bool init_control(void) { char *localhost = NULL; sockaddr_t sa; - socklen_t len = sizeof sa; + 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. @@ -163,7 +163,7 @@ bool init_control(void) { sa.in.sin_addr.s_addr = htonl(0x7f000001); } else if(sa.sa.sa_family == AF_INET6) { static const uint8_t zero[16] = {0}; - if(!memcmp(sa.in6.sin6_addr.s6_addr, zero, sizeof zero)) + if(!memcmp(sa.in6.sin6_addr.s6_addr, zero, sizeof(zero))) sa.in6.sin6_addr.s6_addr[15] = 1; } @@ -184,9 +184,9 @@ bool init_control(void) { struct sockaddr_un sa_un; sa_un.sun_family = AF_UNIX; - strncpy(sa_un.sun_path, unixsocketname, sizeof sa_un.sun_path); + strncpy(sa_un.sun_path, unixsocketname, sizeof(sa_un.sun_path)); - if(connect(unix_fd, (struct sockaddr *)&sa_un, sizeof sa_un) >= 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; } @@ -194,7 +194,7 @@ bool init_control(void) { unlink(unixsocketname); umask(mask | 077); - int result = bind(unix_fd, (struct sockaddr *)&sa_un, sizeof sa_un); + int result = bind(unix_fd, (struct sockaddr *)&sa_un, sizeof(sa_un)); umask(mask); if(result < 0) { diff --git a/src/cygwin/device.c b/src/cygwin/device.c index d3a4303f..64fcc7c8 100644 --- a/src/cygwin/device.c +++ b/src/cygwin/device.c @@ -70,18 +70,18 @@ static bool setup_device(void) { } for (i = 0; ; i++) { - len = sizeof adapterid; + len = sizeof(adapterid); if(RegEnumKeyEx(key, i, adapterid, &len, 0, 0, 0, NULL)) break; /* Find out more about this adapter */ - snprintf(regpath, sizeof regpath, "%s\\%s\\Connection", NETWORK_CONNECTIONS_KEY, adapterid); + snprintf(regpath, sizeof(regpath), "%s\\%s\\Connection", NETWORK_CONNECTIONS_KEY, adapterid); if(RegOpenKeyEx(HKEY_LOCAL_MACHINE, regpath, 0, KEY_READ, &key2)) continue; - len = sizeof adaptername; + len = sizeof(adaptername); err = RegQueryValueEx(key2, "Name", 0, 0, adaptername, &len); RegCloseKey(key2); @@ -105,7 +105,7 @@ static bool setup_device(void) { continue; } - snprintf(tapname, sizeof tapname, USERMODEDEVICEDIR "%s" TAPSUFFIX, adapterid); + snprintf(tapname, sizeof(tapname), USERMODEDEVICEDIR "%s" TAPSUFFIX, adapterid); device_handle = CreateFile(tapname, GENERIC_WRITE | GENERIC_READ, 0, 0, OPEN_EXISTING, FILE_ATTRIBUTE_SYSTEM, 0); if(device_handle != INVALID_HANDLE_VALUE) { CloseHandle(device_handle); @@ -127,7 +127,7 @@ static bool setup_device(void) { if(!iface) iface = xstrdup(adaptername); - snprintf(tapname, sizeof tapname, USERMODEDEVICEDIR "%s" TAPSUFFIX, device); + snprintf(tapname, sizeof(tapname), USERMODEDEVICEDIR "%s" TAPSUFFIX, device); /* Now we are going to open this device twice: once for reading and once for writing. We do this because apparently it isn't possible to check for activity in the select() loop. @@ -151,7 +151,7 @@ static bool setup_device(void) { /* Get MAC address from tap device */ - if(!DeviceIoControl(device_handle, TAP_IOCTL_GET_MAC, mymac.x, sizeof mymac.x, mymac.x, sizeof mymac.x, &len, 0)) { + if(!DeviceIoControl(device_handle, TAP_IOCTL_GET_MAC, mymac.x, sizeof(mymac.x), mymac.x, sizeof mymac.x, &len, 0)) { logger(DEBUG_ALWAYS, LOG_ERR, "Could not get MAC address from Windows tap device %s (%s): %s", device, iface, winerror(GetLastError())); return false; } diff --git a/src/ed25519/ecdh.c b/src/ed25519/ecdh.c index 9adf19fe..302fafd8 100644 --- a/src/ed25519/ecdh.c +++ b/src/ed25519/ecdh.c @@ -31,10 +31,10 @@ typedef struct ecdh_t { #include "../xalloc.h" ecdh_t *ecdh_generate_public(void *pubkey) { - ecdh_t *ecdh = xzalloc(sizeof *ecdh); + ecdh_t *ecdh = xzalloc(sizeof(*ecdh)); uint8_t seed[32]; - randomize(seed, sizeof seed); + randomize(seed, sizeof(seed)); ed25519_create_keypair(pubkey, ecdh->private, seed); return ecdh; diff --git a/src/ed25519/ecdsa.c b/src/ed25519/ecdsa.c index 05b85501..78e24fe6 100644 --- a/src/ed25519/ecdsa.c +++ b/src/ed25519/ecdsa.c @@ -42,7 +42,7 @@ ecdsa_t *ecdsa_set_base64_public_key(const char *p) { return 0; } - ecdsa_t *ecdsa = xzalloc(sizeof *ecdsa); + ecdsa_t *ecdsa = xzalloc(sizeof(*ecdsa)); len = b64decode(p, ecdsa->public, len); if(len != 32) { logger(DEBUG_ALWAYS, LOG_ERR, "Invalid format of public key! len = %d", len); @@ -55,7 +55,7 @@ ecdsa_t *ecdsa_set_base64_public_key(const char *p) { char *ecdsa_get_base64_public_key(ecdsa_t *ecdsa) { char *base64 = xmalloc(44); - b64encode(ecdsa->public, base64, sizeof ecdsa->public); + b64encode(ecdsa->public, base64, sizeof(ecdsa->public)); return base64; } @@ -67,7 +67,7 @@ static bool read_pem(FILE *fp, const char *type, void *buf, size_t size) { bool data = false; size_t typelen = strlen(type); - while(fgets(line, sizeof line, fp)) { + while(fgets(line, sizeof(line), fp)) { if(!data) { if(strncmp(line, "-----BEGIN ", 11)) continue; @@ -113,16 +113,16 @@ static bool read_pem(FILE *fp, const char *type, void *buf, size_t size) { } ecdsa_t *ecdsa_read_pem_public_key(FILE *fp) { - ecdsa_t *ecdsa = xzalloc(sizeof *ecdsa); - if(read_pem(fp, "ED25519 PUBLIC KEY", ecdsa->public, sizeof ecdsa->public)) + ecdsa_t *ecdsa = xzalloc(sizeof(*ecdsa)); + if(read_pem(fp, "ED25519 PUBLIC KEY", ecdsa->public, sizeof(ecdsa->public))) return ecdsa; free(ecdsa); return 0; } ecdsa_t *ecdsa_read_pem_private_key(FILE *fp) { - ecdsa_t *ecdsa = xmalloc(sizeof *ecdsa); - if(read_pem(fp, "ED25519 PRIVATE KEY", ecdsa->private, sizeof *ecdsa)) + ecdsa_t *ecdsa = xmalloc(sizeof(*ecdsa)); + if(read_pem(fp, "ED25519 PRIVATE KEY", ecdsa->private, sizeof(*ecdsa))) return ecdsa; free(ecdsa); return 0; diff --git a/src/ed25519/ecdsagen.c b/src/ed25519/ecdsagen.c index 23ef6e97..5120f287 100644 --- a/src/ed25519/ecdsagen.c +++ b/src/ed25519/ecdsagen.c @@ -35,10 +35,10 @@ typedef struct { // Generate ECDSA key ecdsa_t *ecdsa_generate(void) { - ecdsa_t *ecdsa = xzalloc(sizeof *ecdsa); + ecdsa_t *ecdsa = xzalloc(sizeof(*ecdsa)); uint8_t seed[32]; - randomize(seed, sizeof seed); + randomize(seed, sizeof(seed)); ed25519_create_keypair(ecdsa->public, ecdsa->private, seed); return ecdsa; @@ -63,9 +63,9 @@ static bool write_pem(FILE *fp, const char *type, void *buf, size_t size) { } bool ecdsa_write_pem_public_key(ecdsa_t *ecdsa, FILE *fp) { - return write_pem(fp, "ED25519 PUBLIC KEY", ecdsa->public, sizeof ecdsa->public); + return write_pem(fp, "ED25519 PUBLIC KEY", ecdsa->public, sizeof(ecdsa->public)); } bool ecdsa_write_pem_private_key(ecdsa_t *ecdsa, FILE *fp) { - return write_pem(fp, "ED25519 PRIVATE KEY", ecdsa->private, sizeof *ecdsa); + return write_pem(fp, "ED25519 PRIVATE KEY", ecdsa->private, sizeof(*ecdsa)); } diff --git a/src/event.c b/src/event.c index 858e1d9d..d981f75b 100644 --- a/src/event.c +++ b/src/event.c @@ -258,8 +258,8 @@ bool event_loop(void) { while(running) { struct timeval diff; struct timeval *tv = get_time_remaining(&diff); - memcpy(&readable, &readfds, sizeof readable); - memcpy(&writable, &writefds, sizeof writable); + memcpy(&readable, &readfds, sizeof(readable)); + memcpy(&writable, &writefds, sizeof(writable)); int fds = 0; diff --git a/src/fsck.c b/src/fsck.c index e5e7dd5a..42f40f42 100644 --- a/src/fsck.c +++ b/src/fsck.c @@ -39,7 +39,7 @@ static bool ask_fix(void) { again: fprintf(stderr, "Fix y/n? "); char buf[1024]; - if(!fgets(buf, sizeof buf, stdin)) { + if(!fgets(buf, sizeof(buf), stdin)) { tty = false; return false; } @@ -84,9 +84,9 @@ static void check_conffile(const char *fname, bool server) { bool skip = false; const int maxvariables = 50; int count[maxvariables]; - memset(count, 0, sizeof count); + memset(count, 0, sizeof(count)); - while(fgets(line, sizeof line, f)) { + while(fgets(line, sizeof(line), f)) { if(skip) { if(!strncmp(line, "-----END", 8)) skip = false; @@ -192,7 +192,7 @@ int fsck(const char *argv0) { #ifndef DISABLE_LEGACY rsa_t *rsa_priv = NULL; - snprintf(fname, sizeof fname, "%s/rsa_key.priv", confbase); + snprintf(fname, sizeof(fname), "%s/rsa_key.priv", confbase); if(stat(fname, &st)) { if(errno != ENOENT) { @@ -233,7 +233,7 @@ int fsck(const char *argv0) { #endif ecdsa_t *ecdsa_priv = NULL; - snprintf(fname, sizeof fname, "%s/ed25519_key.priv", confbase); + snprintf(fname, sizeof(fname), "%s/ed25519_key.priv", confbase); if(stat(fname, &st)) { if(errno != ENOENT) { @@ -287,7 +287,7 @@ int fsck(const char *argv0) { // Check for public keys. // TODO: use RSAPublicKeyFile variable if present. - snprintf(fname, sizeof fname, "%s/hosts/%s", confbase, name); + snprintf(fname, sizeof(fname), "%s/hosts/%s", confbase, name); if(access(fname, R_OK)) fprintf(stderr, "WARNING: cannot read %s\n", fname); @@ -325,19 +325,19 @@ int fsck(const char *argv0) { return 1; } char buf1[len], buf2[len], buf3[len]; - randomize(buf1, sizeof buf1); + randomize(buf1, sizeof(buf1)); buf1[0] &= 0x7f; - memset(buf2, 0, sizeof buf2); - memset(buf3, 0, sizeof buf2); - if(!rsa_public_encrypt(rsa_pub, buf1, sizeof buf1, buf2)) { + memset(buf2, 0, sizeof(buf2)); + memset(buf3, 0, sizeof(buf2)); + if(!rsa_public_encrypt(rsa_pub, buf1, sizeof(buf1), buf2)) { fprintf(stderr, "ERROR: public RSA key does not work.\n"); return 1; } - if(!rsa_private_decrypt(rsa_priv, buf2, sizeof buf2, buf3)) { + if(!rsa_private_decrypt(rsa_priv, buf2, sizeof(buf2), buf3)) { fprintf(stderr, "ERROR: private RSA key does not work.\n"); return 1; } - if(memcmp(buf1, buf3, sizeof buf1)) { + if(memcmp(buf1, buf3, sizeof(buf1))) { fprintf(stderr, "ERROR: public and private RSA keys do not match.\n"); return 1; } @@ -414,7 +414,7 @@ int fsck(const char *argv0) { if(strtailcmp(ent->d_name, "-up") && strtailcmp(ent->d_name, "-down")) continue; - strncpy(fname, ent->d_name, sizeof fname); + strncpy(fname, ent->d_name, sizeof(fname)); char *dash = strrchr(fname, '-'); if(!dash) continue; @@ -431,7 +431,7 @@ int fsck(const char *argv0) { continue; } - snprintf(fname, sizeof fname, "%s" SLASH "%s", confbase, ent->d_name); + snprintf(fname, sizeof(fname), "%s" SLASH "%s", confbase, ent->d_name); if(access(fname, R_OK | X_OK)) { if(errno != EACCES) { fprintf(stderr, "ERROR: cannot access %s: %s\n", fname, strerror(errno)); @@ -446,7 +446,7 @@ int fsck(const char *argv0) { } closedir(dir); - snprintf(dname, sizeof dname, "%s" SLASH "hosts", confbase); + snprintf(dname, sizeof(dname), "%s" SLASH "hosts", confbase); dir = opendir(dname); if(!dir) { fprintf(stderr, "ERROR: cannot read directory %s: %s\n", dname, strerror(errno)); @@ -457,13 +457,13 @@ int fsck(const char *argv0) { if(strtailcmp(ent->d_name, "-up") && strtailcmp(ent->d_name, "-down")) continue; - strncpy(fname, ent->d_name, sizeof fname); + strncpy(fname, ent->d_name, sizeof(fname)); char *dash = strrchr(fname, '-'); if(!dash) continue; *dash = 0; - snprintf(fname, sizeof fname, "%s" SLASH "hosts" SLASH "%s", confbase, ent->d_name); + snprintf(fname, sizeof(fname), "%s" SLASH "hosts" SLASH "%s", confbase, ent->d_name); if(access(fname, R_OK | X_OK)) { if(errno != EACCES) { fprintf(stderr, "ERROR: cannot access %s: %s\n", fname, strerror(errno)); @@ -488,7 +488,7 @@ int fsck(const char *argv0) { if(!check_id(ent->d_name)) continue; - snprintf(fname, sizeof fname, "%s" SLASH "hosts" SLASH "%s", confbase, ent->d_name); + snprintf(fname, sizeof(fname), "%s" SLASH "hosts" SLASH "%s", confbase, ent->d_name); check_conffile(fname, false); } closedir(dir); diff --git a/src/gcrypt/cipher.c b/src/gcrypt/cipher.c index e9b32cf7..b9b32244 100644 --- a/src/gcrypt/cipher.c +++ b/src/gcrypt/cipher.c @@ -55,7 +55,7 @@ static struct { static bool nametocipher(const char *name, int *algo, int *mode) { size_t i; - for(i = 0; i < sizeof ciphertable / sizeof *ciphertable; i++) { + for(i = 0; i < sizeof(ciphertable) / sizeof *ciphertable; i++) { if(ciphertable[i].name && !strcasecmp(name, ciphertable[i].name)) { *algo = ciphertable[i].algo; *mode = ciphertable[i].mode; @@ -69,7 +69,7 @@ static bool nametocipher(const char *name, int *algo, int *mode) { static bool nidtocipher(int nid, int *algo, int *mode) { size_t i; - for(i = 0; i < sizeof ciphertable / sizeof *ciphertable; i++) { + for(i = 0; i < sizeof(ciphertable) / sizeof *ciphertable; i++) { if(nid == ciphertable[i].nid) { *algo = ciphertable[i].algo; *mode = ciphertable[i].mode; @@ -83,7 +83,7 @@ static bool nidtocipher(int nid, int *algo, int *mode) { static bool ciphertonid(int algo, int mode, int *nid) { size_t i; - for(i = 0; i < sizeof ciphertable / sizeof *ciphertable; i++) { + for(i = 0; i < sizeof(ciphertable) / sizeof *ciphertable; i++) { if(algo == ciphertable[i].algo && mode == ciphertable[i].mode) { *nid = ciphertable[i].nid; return true; diff --git a/src/gcrypt/digest.c b/src/gcrypt/digest.c index 4229b0c8..60b9569f 100644 --- a/src/gcrypt/digest.c +++ b/src/gcrypt/digest.c @@ -37,7 +37,7 @@ static struct { static bool nametodigest(const char *name, int *algo) { int i; - for(i = 0; i < sizeof digesttable / sizeof *digesttable; i++) { + for(i = 0; i < sizeof(digesttable) / sizeof *digesttable; i++) { if(digesttable[i].name && !strcasecmp(name, digesttable[i].name)) { *algo = digesttable[i].algo; return true; @@ -50,7 +50,7 @@ static bool nametodigest(const char *name, int *algo) { static bool nidtodigest(int nid, int *algo) { int i; - for(i = 0; i < sizeof digesttable / sizeof *digesttable; i++) { + for(i = 0; i < sizeof(digesttable) / sizeof *digesttable; i++) { if(nid == digesttable[i].nid) { *algo = digesttable[i].algo; return true; @@ -63,7 +63,7 @@ static bool nidtodigest(int nid, int *algo) { static bool digesttonid(int algo, int *nid) { int i; - for(i = 0; i < sizeof digesttable / sizeof *digesttable; i++) { + for(i = 0; i < sizeof(digesttable) / sizeof *digesttable; i++) { if(algo == digesttable[i].algo) { *nid = digesttable[i].nid; return true; diff --git a/src/gcrypt/prf.c b/src/gcrypt/prf.c index 55c9923d..1937f675 100644 --- a/src/gcrypt/prf.c +++ b/src/gcrypt/prf.c @@ -60,7 +60,7 @@ static bool hmac_sha512(const char *key, size_t keylen, const char *msg, size_t // opad memxor(tmp, 0x36 ^ 0x5c, blklen); - if(sha512(tmp, sizeof tmp, out) != 0) + if(sha512(tmp, sizeof(tmp), out) != 0) return false; return true; @@ -84,17 +84,17 @@ bool prf(const char *secret, size_t secretlen, char *seed, size_t seedlen, char while(outlen > 0) { /* Inner HMAC */ - if(!hmac_sha512(secret, secretlen, data, sizeof data, data)) + if(!hmac_sha512(secret, secretlen, data, sizeof(data), data)) return false; /* Outer HMAC */ if(outlen >= mdlen) { - if(!hmac_sha512(secret, secretlen, data, sizeof data, out)) + if(!hmac_sha512(secret, secretlen, data, sizeof(data), out)) return false; out += mdlen; outlen -= mdlen; } else { - if(!hmac_sha512(secret, secretlen, data, sizeof data, hash)) + if(!hmac_sha512(secret, secretlen, data, sizeof(data), hash)) return false; memcpy(out, hash, outlen); out += outlen; diff --git a/src/gcrypt/rsa.c b/src/gcrypt/rsa.c index 751f7b6b..d354b0c2 100644 --- a/src/gcrypt/rsa.c +++ b/src/gcrypt/rsa.c @@ -61,7 +61,7 @@ static bool pem_decode(FILE *fp, const char *header, uint8_t *buf, size_t size, size_t i, j = 0; while(!feof(fp)) { - if(!fgets(line, sizeof line, fp)) + if(!fgets(line, sizeof(line), fp)) return false; if(!decode && !strncmp(line, "-----BEGIN ", 11)) { @@ -215,7 +215,7 @@ bool rsa_read_pem_public_key(rsa_t *rsa, FILE *fp) { uint8_t derbuf[8096], *derp = derbuf; size_t derlen; - if(!pem_decode(fp, "RSA PUBLIC KEY", derbuf, sizeof derbuf, &derlen)) { + if(!pem_decode(fp, "RSA PUBLIC KEY", derbuf, sizeof(derbuf), &derlen)) { logger(DEBUG_ALWAYS, LOG_ERR, "Unable to read RSA public key: %s", strerror(errno)); return NULL; } @@ -235,7 +235,7 @@ bool rsa_read_pem_private_key(rsa_t *rsa, FILE *fp) { uint8_t derbuf[8096], *derp = derbuf; size_t derlen; - if(!pem_decode(fp, "RSA PRIVATE KEY", derbuf, sizeof derbuf, &derlen)) { + if(!pem_decode(fp, "RSA PRIVATE KEY", derbuf, sizeof(derbuf), &derlen)) { logger(DEBUG_ALWAYS, LOG_ERR, "Unable to read RSA private key: %s", strerror(errno)); return NULL; } diff --git a/src/gcrypt/rsagen.c b/src/gcrypt/rsagen.c index 36fb1044..dfbfa338 100644 --- a/src/gcrypt/rsagen.c +++ b/src/gcrypt/rsagen.c @@ -134,7 +134,7 @@ static bool ber_write_sequence(uint8_t **p, size_t *buflen, uint8_t *seqbuf, siz static bool ber_write_mpi(uint8_t **p, size_t *buflen, gcry_mpi_t mpi) { uint8_t tmpbuf[1024]; - size_t tmplen = sizeof tmpbuf; + size_t tmplen = sizeof(tmpbuf); gcry_error_t err; err = gcry_mpi_aprint(GCRYMPI_FMT_USG, &tmpbuf, &tmplen, mpi); @@ -158,8 +158,8 @@ bool rsa_write_pem_public_key(rsa_t *rsa, FILE *fp) { uint8_t derbuf2[8096]; uint8_t *derp1 = derbuf1; uint8_t *derp2 = derbuf2; - size_t derlen1 = sizeof derbuf1; - size_t derlen2 = sizeof derbuf2; + size_t derlen1 = sizeof(derbuf1); + size_t derlen2 = sizeof(derbuf2); if(!ber_write_mpi(&derp1, &derlen1, &rsa->n) || !ber_write_mpi(&derp1, &derlen1, &rsa->e) @@ -181,8 +181,8 @@ bool rsa_write_pem_private_key(rsa_t *rsa, FILE *fp) { uint8_t derbuf2[8096]; uint8_t *derp1 = derbuf1; uint8_t *derp2 = derbuf2; - size_t derlen1 = sizeof derbuf1; - size_t derlen2 = sizeof derbuf2; + size_t derlen1 = sizeof(derbuf1); + size_t derlen2 = sizeof(derbuf2); if(!ber_write_mpi(&derp1, &derlen1, &bits) || ber_write_mpi(&derp1, &derlen1, &rsa->n) // modulus diff --git a/src/graph.c b/src/graph.c index 1f1fdb3d..e6cd011f 100644 --- a/src/graph.c +++ b/src/graph.c @@ -269,7 +269,7 @@ static void check_reachability(void) { if(!n->status.reachable) { update_node_udp(n, NULL); - memset(&n->status, 0, sizeof n->status); + memset(&n->status, 0, sizeof(n->status)); n->options = 0; } else if(n->connection) { // Speed up UDP probing by sending our key. diff --git a/src/hash.c b/src/hash.c index 50934d9b..f27b2573 100644 --- a/src/hash.c +++ b/src/hash.c @@ -52,11 +52,11 @@ static uint32_t modulo(uint32_t hash, size_t n) { /* (De)allocation */ hash_t *hash_alloc(size_t n, size_t size) { - hash_t *hash = xzalloc(sizeof *hash); + hash_t *hash = xzalloc(sizeof(*hash)); hash->n = n; hash->size = size; hash->keys = xzalloc(hash->n * hash->size); - hash->values = xzalloc(hash->n * sizeof *hash->values); + hash->values = xzalloc(hash->n * sizeof(*hash->values)); return hash; } @@ -101,14 +101,14 @@ void hash_delete(hash_t *hash, const void *key) { /* Utility functions */ void hash_clear(hash_t *hash) { - memset(hash->values, 0, hash->n * sizeof *hash->values); + memset(hash->values, 0, hash->n * sizeof(*hash->values)); } void hash_resize(hash_t *hash, size_t n) { hash->keys = xrealloc(hash->keys, n * hash->size); - hash->values = xrealloc(hash->values, n * sizeof *hash->values); + hash->values = xrealloc(hash->values, n * sizeof(*hash->values)); if(n > hash->n) { memset(hash->keys + hash->n * hash->size, 0, (n - hash->n) * hash->size); - memset(hash->values + hash->n, 0, (n - hash->n) * sizeof *hash->values); + memset(hash->values + hash->n, 0, (n - hash->n) * sizeof(*hash->values)); } } diff --git a/src/ifconfig.c b/src/ifconfig.c index 0b99402b..c03fef46 100644 --- a/src/ifconfig.c +++ b/src/ifconfig.c @@ -88,7 +88,7 @@ static subnet_t ipv4, ipv6; void ifconfig_address(FILE *out, const char *value) { subnet_t address = {}; char address_str[MAXNETSTR]; - if(!str2net(&address, value) || !net2str(address_str, sizeof address_str, &address)) { + if(!str2net(&address, value) || !net2str(address_str, sizeof(address_str), &address)) { fprintf(stderr, "Could not parse address in Ifconfig statement\n"); return; } @@ -127,12 +127,12 @@ void ifconfig_route(FILE *out, const char *value) { char *sep = strchr(value, ' '); if(sep) *sep++ = 0; - if(!str2net(&subnet, value) || !net2str(subnet_str, sizeof subnet_str, &subnet) || subnet.type == SUBNET_MAC) { + if(!str2net(&subnet, value) || !net2str(subnet_str, sizeof(subnet_str), &subnet) || subnet.type == SUBNET_MAC) { fprintf(stderr, "Could not parse subnet in Route statement\n"); return; } if(sep) { - if(!str2net(&gateway, sep) || !net2str(gateway_str, sizeof gateway_str, &gateway) || gateway.type != subnet.type) { + if(!str2net(&gateway, sep) || !net2str(gateway_str, sizeof(gateway_str), &gateway) || gateway.type != subnet.type) { fprintf(stderr, "Could not parse gateway in Route statement\n"); return; } @@ -174,14 +174,14 @@ void ifconfig_route(FILE *out, const char *value) { fprintf(stderr, "Route requested but no Ifconfig\n"); return; } - net2str(gateway_str, sizeof gateway_str, &ipv4); + net2str(gateway_str, sizeof(gateway_str), &ipv4); break; case SUBNET_IPV6: if(!ipv6.type) { fprintf(stderr, "Route requested but no Ifconfig\n"); return; } - net2str(gateway_str, sizeof gateway_str, &ipv6); + net2str(gateway_str, sizeof(gateway_str), &ipv6); break; default: return; } diff --git a/src/info.c b/src/info.c index 2a6934b4..b5525748 100644 --- a/src/info.c +++ b/src/info.c @@ -68,7 +68,7 @@ static int info_node(int fd, const char *item) { node_status_t status; long int last_state_change; - while(recvline(fd, line, sizeof line)) { + while(recvline(fd, line, sizeof(line))) { int n = sscanf(line, "%d %d %4095s %4095s %4095s port %4095s %d %d %d %d %x %"PRIx32" %4095s %4095s %d %hd %hd %hd %ld", &code, &req, node, id, host, port, &cipher, &digest, &maclength, &compression, &options, &status_union.raw, nexthop, via, &distance, &pmtu, &minmtu, &maxmtu, &last_state_change); if(n == 2) @@ -90,7 +90,7 @@ static int info_node(int fd, const char *item) { return 1; } - while(recvline(fd, line, sizeof line)) { + while(recvline(fd, line, sizeof(line))) { if(sscanf(line, "%d %d %4095s", &code, &req, node) == 2) break; } @@ -103,7 +103,7 @@ static int info_node(int fd, const char *item) { time_t lsc_time = last_state_change; if(last_state_change) - strftime(timestr, sizeof timestr, "%Y-%m-%d %H:%M:%S", localtime(&lsc_time)); + strftime(timestr, sizeof(timestr), "%Y-%m-%d %H:%M:%S", localtime(&lsc_time)); status = status_union.bits; @@ -157,7 +157,7 @@ static int info_node(int fd, const char *item) { // List edges printf("Edges: "); sendline(fd, "%d %d %s", CONTROL, REQ_DUMP_EDGES, item); - while(recvline(fd, line, sizeof line)) { + while(recvline(fd, line, sizeof(line))) { int n = sscanf(line, "%d %d %4095s %4095s", &code, &req, from, to); if(n == 2) break; @@ -173,7 +173,7 @@ static int info_node(int fd, const char *item) { // List subnets printf("Subnets: "); sendline(fd, "%d %d %s", CONTROL, REQ_DUMP_SUBNETS, item); - while(recvline(fd, line, sizeof line)) { + while(recvline(fd, line, sizeof(line))) { int n = sscanf(line, "%d %d %4095s %4095s", &code, &req, subnet, from); if(n == 2) break; @@ -208,7 +208,7 @@ static int info_subnet(int fd, const char *item) { int code, req; sendline(fd, "%d %d %s", CONTROL, REQ_DUMP_SUBNETS, item); - while(recvline(fd, line, sizeof line)) { + while(recvline(fd, line, sizeof(line))) { int n = sscanf(line, "%d %d %4095s %4095s", &code, &req, netstr, owner); if(n == 2) break; @@ -233,7 +233,7 @@ static int info_subnet(int fd, const char *item) { } else { if(find.net.ipv4.prefixlength != subnet.net.ipv4.prefixlength) continue; - if(memcmp(&find.net.ipv4.address, &subnet.net.ipv4.address, sizeof subnet.net.ipv4)) + if(memcmp(&find.net.ipv4.address, &subnet.net.ipv4.address, sizeof(subnet.net.ipv4))) continue; } } else if(find.type == SUBNET_IPV6) { @@ -243,11 +243,11 @@ static int info_subnet(int fd, const char *item) { } else { if(find.net.ipv6.prefixlength != subnet.net.ipv6.prefixlength) continue; - if(memcmp(&find.net.ipv6.address, &subnet.net.ipv6.address, sizeof subnet.net.ipv6)) + if(memcmp(&find.net.ipv6.address, &subnet.net.ipv6.address, sizeof(subnet.net.ipv6))) continue; } } if(find.type == SUBNET_MAC) { - if(memcmp(&find.net.mac.address, &subnet.net.mac.address, sizeof subnet.net.mac)) + if(memcmp(&find.net.mac.address, &subnet.net.mac.address, sizeof(subnet.net.mac))) continue; } diff --git a/src/invitation.c b/src/invitation.c index 0dfd9eac..2990c474 100644 --- a/src/invitation.c +++ b/src/invitation.c @@ -47,7 +47,7 @@ static void scan_for_hostname(const char *filename, char **hostname, char **port if(!f) return; - while(fgets(line, sizeof line, f)) { + while(fgets(line, sizeof(line), f)) { if(!rstrip(line)) continue; char *p = line, *q; @@ -90,7 +90,7 @@ char *get_my_hostname() { // Use first Address statement in own host config file if(check_id(name)) { - snprintf(filename, sizeof filename, "%s" SLASH "hosts" SLASH "%s", confbase, name); + snprintf(filename, sizeof(filename), "%s" SLASH "hosts" SLASH "%s", confbase, name); scan_for_hostname(filename, &hostname, &port); scan_for_hostname(tinc_conf, &hostname, &port); } @@ -113,8 +113,8 @@ char *get_my_hostname() { } } if(s >= 0) { - send(s, request, sizeof request - 1, 0); - int len = recv(s, line, sizeof line - 1, MSG_WAITALL); + send(s, request, sizeof(request) - 1, 0); + int len = recv(s, line, sizeof(line) - 1, MSG_WAITALL); if(len > 0) { line[len] = 0; if(line[len - 1] == '\n') @@ -160,7 +160,7 @@ again: fprintf(stderr, " [%s]", hostname); fprintf(stderr, ": "); - if(!fgets(line, sizeof line, stdin)) { + if(!fgets(line, sizeof(line), stdin)) { fprintf(stderr, "Error while reading stdin: %s\n", strerror(errno)); free(hostname); return NULL; @@ -221,7 +221,7 @@ static bool fcopy(FILE *out, const char *filename) { char buf[1024]; size_t len; - while((len = fread(buf, 1, sizeof buf, in))) + while((len = fread(buf, 1, sizeof(buf), in))) fwrite(buf, len, 1, out); fclose(in); return true; @@ -245,7 +245,7 @@ int cmd_invite(int argc, char *argv[]) { // Ensure no host configuration file with that name exists char filename[PATH_MAX]; - snprintf(filename, sizeof filename, "%s" SLASH "hosts" SLASH "%s", confbase, argv[1]); + snprintf(filename, sizeof(filename), "%s" SLASH "hosts" SLASH "%s", confbase, argv[1]); if(!access(filename, F_OK)) { fprintf(stderr, "A host config file for %s already exists!\n", argv[1]); return 1; @@ -256,7 +256,7 @@ int cmd_invite(int argc, char *argv[]) { bool found = false; sendline(fd, "%d %d", CONTROL, REQ_DUMP_NODES); - while(recvline(fd, line, sizeof line)) { + while(recvline(fd, line, sizeof(line))) { char node[4096]; int code, req; if(sscanf(line, "%d %d %4095s", &code, &req, node) != 3) @@ -271,7 +271,7 @@ int cmd_invite(int argc, char *argv[]) { } } - snprintf(filename, sizeof filename, "%s" SLASH "invitations", confbase); + snprintf(filename, sizeof(filename), "%s" SLASH "invitations", confbase); if(mkdir(filename, 0700) && errno != EEXIST) { fprintf(stderr, "Could not create directory %s: %s\n", filename, strerror(errno)); return 1; @@ -294,7 +294,7 @@ int cmd_invite(int argc, char *argv[]) { continue; char invname[PATH_MAX]; struct stat st; - snprintf(invname, sizeof invname, "%s" SLASH "%s", filename, ent->d_name); + snprintf(invname, sizeof(invname), "%s" SLASH "%s", filename, ent->d_name); if(!stat(invname, &st)) { if(deadline < st.st_mtime) count++; @@ -314,7 +314,7 @@ int cmd_invite(int argc, char *argv[]) { } ecdsa_t *key; - snprintf(filename, sizeof filename, "%s" SLASH "invitations" SLASH "ed25519_key.priv", confbase); + snprintf(filename, sizeof(filename), "%s" SLASH "invitations" SLASH "ed25519_key.priv", confbase); // Remove the key if there are no outstanding invitations. if(!count) @@ -370,14 +370,14 @@ int cmd_invite(int argc, char *argv[]) { char buf[18 + strlen(fingerprint)]; char cookiehash[64]; memcpy(buf, cookie, 18); - memcpy(buf + 18, fingerprint, sizeof buf - 18); - sha512(buf, sizeof buf, cookiehash); + memcpy(buf + 18, fingerprint, sizeof(buf) - 18); + sha512(buf, sizeof(buf), cookiehash); b64encode_urlsafe(cookiehash, cookiehash, 18); b64encode_urlsafe(cookie, cookie, 18); // Create a file containing the details of the invitation. - snprintf(filename, sizeof filename, "%s" SLASH "invitations" SLASH "%s", confbase, cookiehash); + snprintf(filename, sizeof(filename), "%s" SLASH "invitations" SLASH "%s", confbase, cookiehash); int ifd = open(filename, O_RDWR | O_CREAT | O_EXCL, 0600); if(!ifd) { fprintf(stderr, "Could not create invitation file %s: %s\n", filename, strerror(errno)); @@ -400,7 +400,7 @@ int cmd_invite(int argc, char *argv[]) { FILE *tc = fopen(tinc_conf, "r"); if(tc) { char buf[1024]; - while(fgets(buf, sizeof buf, tc)) { + while(fgets(buf, sizeof(buf), tc)) { if((!strncasecmp(buf, "Mode", 4) && strchr(" \t=", buf[4])) || (!strncasecmp(buf, "Broadcast", 9) && strchr(" \t=", buf[9]))) { fputs(buf, f); @@ -416,7 +416,7 @@ int cmd_invite(int argc, char *argv[]) { fprintf(f, "Name = %s\n", myname); char filename2[PATH_MAX]; - snprintf(filename2, sizeof filename2, "%s" SLASH "hosts" SLASH "%s", confbase, myname); + snprintf(filename2, sizeof(filename2), "%s" SLASH "hosts" SLASH "%s", confbase, myname); fcopy(f, filename2); fclose(f); @@ -461,7 +461,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); - if(len >= sizeof line) { + if(len >= sizeof(line)) { fprintf(stderr, "Maximum line length exceeded!\n"); return NULL; } @@ -521,7 +521,7 @@ static char *grep(const char *data, const char *var) { if(!e) return xstrdup(p); - if(e - p >= sizeof value) { + if(e - p >= sizeof(value)) { fprintf(stderr, "Maximum line length exceeded!\n"); return NULL; } @@ -575,7 +575,7 @@ make_names: // Generate a random netname, ask for a better one later. ask_netname = true; - snprintf(temp_netname, sizeof temp_netname, "join_%x", rand()); + snprintf(temp_netname, sizeof(temp_netname), "join_%x", rand()); netname = temp_netname; goto make_names; } @@ -599,7 +599,7 @@ make_names: fprintf(f, "Name = %s\n", name); char filename[PATH_MAX]; - snprintf(filename, sizeof filename, "%s" SLASH "%s", hosts_dir, name); + snprintf(filename, sizeof(filename), "%s" SLASH "%s", hosts_dir, name); FILE *fh = fopen(filename, "w"); if(!fh) { fprintf(stderr, "Could not create file %s: %s\n", filename, strerror(errno)); @@ -607,7 +607,7 @@ make_names: return false; } - snprintf(filename, sizeof filename, "%s" SLASH "invitation-data", confbase); + snprintf(filename, sizeof(filename), "%s" SLASH "invitation-data", confbase); FILE *finv = fopen(filename, "w"); if(!finv || fwrite(data, datalen, 1, finv) != 1) { fprintf(stderr, "Could not create file %s: %s\n", filename, strerror(errno)); @@ -618,7 +618,7 @@ make_names: } fclose(finv); - snprintf(filename, sizeof filename, "%s" SLASH "tinc-up.invitation", confbase); + snprintf(filename, sizeof(filename), "%s" SLASH "tinc-up.invitation", confbase); FILE *fup = fopen(filename, "w"); if(!fup) { fprintf(stderr, "Could not create file %s: %s\n", filename, strerror(errno)); @@ -715,7 +715,7 @@ make_names: return false; } - snprintf(filename, sizeof filename, "%s" SLASH "%s", hosts_dir, value); + snprintf(filename, sizeof(filename), "%s" SLASH "%s", hosts_dir, value); f = fopen(filename, "w"); if(!f) { @@ -754,7 +754,7 @@ make_names: if(!b64key) return false; - snprintf(filename, sizeof filename, "%s" SLASH "ed25519_key.priv", confbase); + snprintf(filename, sizeof(filename), "%s" SLASH "ed25519_key.priv", confbase); f = fopenmask(filename, "w", 0600); if(!f) return false; @@ -776,7 +776,7 @@ make_names: #ifndef DISABLE_LEGACY rsa_t *rsa = rsa_generate(2048, 0x1001); - snprintf(filename, sizeof filename, "%s" SLASH "rsa_key.priv", confbase); + snprintf(filename, sizeof(filename), "%s" SLASH "rsa_key.priv", confbase); f = fopenmask(filename, "w", 0600); if(!f || !rsa_write_pem_private_key(rsa, f)) { @@ -797,7 +797,7 @@ make_names: ask_netname: if(ask_netname && tty) { fprintf(stderr, "Enter a new netname: "); - if(!fgets(line, sizeof line, stdin)) { + if(!fgets(line, sizeof(line), stdin)) { fprintf(stderr, "Error while reading stdin: %s\n", strerror(errno)); return false; } @@ -807,7 +807,7 @@ ask_netname: line[strlen(line) - 1] = 0; char newbase[PATH_MAX]; - snprintf(newbase, sizeof newbase, CONFDIR SLASH "tinc" SLASH "%s", line); + snprintf(newbase, sizeof(newbase), CONFDIR SLASH "tinc" SLASH "%s", line); if(rename(confbase, newbase)) { fprintf(stderr, "Error trying to rename %s to %s: %s\n", confbase, newbase, strerror(errno)); goto ask_netname; @@ -818,8 +818,8 @@ ask_netname: } char filename2[PATH_MAX]; - snprintf(filename, sizeof filename, "%s" SLASH "tinc-up.invitation", confbase); - snprintf(filename2, sizeof filename2, "%s" SLASH "tinc-up", confbase); + snprintf(filename, sizeof(filename), "%s" SLASH "tinc-up.invitation", confbase); + snprintf(filename2, sizeof(filename2), "%s" SLASH "tinc-up", confbase); if(valid_tinc_up) { if(tty) { @@ -828,7 +828,7 @@ ask_netname: fprintf(stderr, "\nPlease review the following tinc-up script:\n\n"); char buf[MAXSIZE]; - while(fgets(buf, sizeof buf, fup)) + while(fgets(buf, sizeof(buf), fup)) fputs(buf, stderr); fclose(fup); @@ -893,7 +893,7 @@ 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) { switch(type) { case SPTPS_HANDSHAKE: - return sptps_send_record(&sptps, 0, cookie, sizeof cookie); + return sptps_send_record(&sptps, 0, cookie, sizeof(cookie)); case 0: data = xrealloc(data, datalen + len + 1); @@ -959,7 +959,7 @@ int cmd_join(int argc, char *argv[]) { if(tty) fprintf(stderr, "Enter invitation URL: "); errno = EPIPE; - if(!fgets(line, sizeof line, stdin)) { + if(!fgets(line, sizeof(line), stdin)) { fprintf(stderr, "Error while reading stdin: %s\n", strerror(errno)); return false; } @@ -1042,8 +1042,8 @@ next: fprintf(stderr, "Connected to %s port %s...\n", address, port); // 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) + int len = snprintf(line, sizeof(line), "0 ?%s %d.%d\n", b64key, PROT_MAJOR, PROT_MINOR); + if(len <= 0 || len >= sizeof(line)) abort(); if(!sendline(sock, "0 ?%s %d.%d", b64key, PROT_MAJOR, 1)) { @@ -1055,7 +1055,7 @@ next: char hisname[4096] = ""; int code, hismajor, hisminor = 0; - if(!recvline(sock, line, sizeof line) || sscanf(line, "%d %4095s %d.%d", &code, hisname, &hismajor, &hisminor) < 3 || code != 0 || hismajor != PROT_MAJOR || !check_id(hisname) || !recvline(sock, line, sizeof line) || !rstrip(line) || sscanf(line, "%d ", &code) != 1 || code != ACK || strlen(line) < 3) { + if(!recvline(sock, line, sizeof(line)) || sscanf(line, "%d %4095s %d.%d", &code, hisname, &hismajor, &hisminor) < 3 || code != 0 || hismajor != PROT_MAJOR || !check_id(hisname) || !recvline(sock, line, sizeof line) || !rstrip(line) || sscanf(line, "%d ", &code) != 1 || code != ACK || strlen(line) < 3) { fprintf(stderr, "Cannot read greeting from peer\n"); closesocket(sock); goto next; @@ -1086,7 +1086,7 @@ next: if(!sptps_receive_data(&sptps, buffer, blen)) return 1; - while((len = recv(sock, line, sizeof line, 0))) { + while((len = recv(sock, line, sizeof(line), 0))) { if(len < 0) { if(errno == EINTR) continue; diff --git a/src/logger.c b/src/logger.c index 4075ea8c..70180f7c 100644 --- a/src/logger.c +++ b/src/logger.c @@ -61,7 +61,7 @@ static void real_logger(int level, int priority, const char *message) { if(!now.tv_sec) gettimeofday(&now, NULL); time_t now_sec = now.tv_sec; - strftime(timestr, sizeof timestr, "%Y-%m-%d %H:%M:%S", localtime(&now_sec)); + strftime(timestr, sizeof(timestr), "%Y-%m-%d %H:%M:%S", localtime(&now_sec)); fprintf(logfile, "%s %s[%ld]: %s\n", timestr, logident, (long)logpid, message); fflush(logfile); break; @@ -109,11 +109,11 @@ void logger(int level, int priority, const char *format, ...) { char message[1024] = ""; va_start(ap, format); - int len = vsnprintf(message, sizeof message, format, ap); - message[sizeof message - 1] = 0; + int len = vsnprintf(message, sizeof(message), format, ap); + message[sizeof(message) - 1] = 0; va_end(ap); - if(len > 0 && len < sizeof message - 1 && message[len - 1] == '\n') + if(len > 0 && len < sizeof(message) - 1 && message[len - 1] == '\n') message[len - 1] = 0; real_logger(level, priority, message); @@ -121,11 +121,11 @@ 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) { char message[1024]; - size_t msglen = sizeof message; + size_t msglen = sizeof(message); int len = vsnprintf(message, msglen, format, ap); - message[sizeof message - 1] = 0; - if(len > 0 && len < sizeof message - 1) { + message[sizeof(message) - 1] = 0; + if(len > 0 && len < sizeof(message) - 1) { if(message[len - 1] == '\n') message[--len] = 0; @@ -133,7 +133,7 @@ static void sptps_logger(sptps_t *s, int s_errno, const char *format, va_list ap // but both types have the name and hostname fields at the same offsets. connection_t *c = s->handle; if(c) - snprintf(message + len, sizeof message - len, " from %s (%s)", c->name, c->hostname); + snprintf(message + len, sizeof(message) - len, " from %s (%s)", c->name, c->hostname); } real_logger(DEBUG_ALWAYS, LOG_ERR, message); diff --git a/src/meta.c b/src/meta.c index 4b357982..81919832 100644 --- a/src/meta.c +++ b/src/meta.c @@ -164,12 +164,12 @@ bool receive_meta(connection_t *c) { buffer_compact(&c->inbuf, MAXBUFSIZE); - if(sizeof inbuf <= c->inbuf.len) { + if(sizeof(inbuf) <= c->inbuf.len) { logger(DEBUG_ALWAYS, LOG_ERR, "Input buffer full for %s (%s)", c->name, c->hostname); return false; } - inlen = recv(c->socket, inbuf, sizeof inbuf - c->inbuf.len, 0); + inlen = recv(c->socket, inbuf, sizeof(inbuf) - c->inbuf.len, 0); if(inlen <= 0) { if(!inlen || !sockerrno) { diff --git a/src/mingw/device.c b/src/mingw/device.c index dfdb9641..9c79ac05 100644 --- a/src/mingw/device.c +++ b/src/mingw/device.c @@ -112,18 +112,18 @@ static bool setup_device(void) { } for (i = 0; ; i++) { - len = sizeof adapterid; + len = sizeof(adapterid); if(RegEnumKeyEx(key, i, adapterid, &len, 0, 0, 0, NULL)) break; /* Find out more about this adapter */ - snprintf(regpath, sizeof regpath, "%s\\%s\\Connection", NETWORK_CONNECTIONS_KEY, adapterid); + snprintf(regpath, sizeof(regpath), "%s\\%s\\Connection", NETWORK_CONNECTIONS_KEY, adapterid); if(RegOpenKeyEx(HKEY_LOCAL_MACHINE, regpath, 0, KEY_READ, &key2)) continue; - len = sizeof adaptername; + len = sizeof(adaptername); err = RegQueryValueEx(key2, "Name", 0, 0, (LPBYTE)adaptername, &len); RegCloseKey(key2); @@ -147,7 +147,7 @@ static bool setup_device(void) { continue; } - snprintf(tapname, sizeof tapname, USERMODEDEVICEDIR "%s" TAPSUFFIX, adapterid); + snprintf(tapname, sizeof(tapname), USERMODEDEVICEDIR "%s" TAPSUFFIX, adapterid); device_handle = CreateFile(tapname, GENERIC_WRITE | GENERIC_READ, 0, 0, OPEN_EXISTING, FILE_ATTRIBUTE_SYSTEM | FILE_FLAG_OVERLAPPED, 0); if(device_handle != INVALID_HANDLE_VALUE) { found = true; @@ -171,7 +171,7 @@ static bool setup_device(void) { /* Try to open the corresponding tap device */ if(device_handle == INVALID_HANDLE_VALUE) { - snprintf(tapname, sizeof tapname, USERMODEDEVICEDIR "%s" TAPSUFFIX, device); + snprintf(tapname, sizeof(tapname), USERMODEDEVICEDIR "%s" TAPSUFFIX, device); device_handle = CreateFile(tapname, GENERIC_WRITE | GENERIC_READ, 0, 0, OPEN_EXISTING, FILE_ATTRIBUTE_SYSTEM | FILE_FLAG_OVERLAPPED, 0); } @@ -185,7 +185,7 @@ static bool setup_device(void) { { ULONG info[3] = {0}; DWORD len; - if(!DeviceIoControl(device_handle, TAP_IOCTL_GET_VERSION, &info, sizeof info, &info, sizeof info, &len, NULL)) + if(!DeviceIoControl(device_handle, TAP_IOCTL_GET_VERSION, &info, sizeof(info), &info, sizeof info, &len, NULL)) logger(DEBUG_ALWAYS, LOG_WARNING, "Could not get version information from Windows tap device %s (%s): %s", device, iface, winerror(GetLastError())); else { logger(DEBUG_ALWAYS, LOG_INFO, "TAP-Windows driver version: %lu.%lu%s", info[0], info[1], info[2] ? " (DEBUG)" : ""); @@ -201,7 +201,7 @@ static bool setup_device(void) { /* Get MAC address from tap device */ - if(!DeviceIoControl(device_handle, TAP_IOCTL_GET_MAC, mymac.x, sizeof mymac.x, mymac.x, sizeof mymac.x, &len, 0)) { + if(!DeviceIoControl(device_handle, TAP_IOCTL_GET_MAC, mymac.x, sizeof(mymac.x), mymac.x, sizeof mymac.x, &len, 0)) { logger(DEBUG_ALWAYS, LOG_ERR, "Could not get MAC address from Windows tap device %s (%s): %s", device, iface, winerror(GetLastError())); return false; } @@ -225,7 +225,7 @@ static void enable_device(void) { ULONG status = 1; DWORD len; - DeviceIoControl(device_handle, TAP_IOCTL_SET_MEDIA_STATUS, &status, sizeof status, &status, sizeof status, &len, NULL); + DeviceIoControl(device_handle, TAP_IOCTL_SET_MEDIA_STATUS, &status, sizeof(status), &status, sizeof status, &len, NULL); /* We don't use the write event directly, but GetOverlappedResult() does, internally. */ @@ -240,7 +240,7 @@ static void disable_device(void) { ULONG status = 0; DWORD len; - DeviceIoControl(device_handle, TAP_IOCTL_SET_MEDIA_STATUS, &status, sizeof status, &status, sizeof status, &len, NULL); + DeviceIoControl(device_handle, TAP_IOCTL_SET_MEDIA_STATUS, &status, sizeof(status), &status, sizeof status, &len, NULL); /* Note that we don't try to cancel ongoing I/O here - we just stop listening. This is because some TAP-Win32 drivers don't seem to handle cancellation very well, @@ -297,7 +297,7 @@ static bool write_packet(vpn_packet_t *packet) { /* Copy the packet, since the write operation might still be ongoing after we return. */ - memcpy(&device_write_packet, packet, sizeof *packet); + memcpy(&device_write_packet, packet, sizeof(*packet)); if(WriteFile(device_handle, DATA(&device_write_packet), device_write_packet.len, &outlen, &device_write_overlapped)) device_write_packet.len = 0; diff --git a/src/multicast_device.c b/src/multicast_device.c index 8dab9e06..082ba7d8 100644 --- a/src/multicast_device.c +++ b/src/multicast_device.c @@ -80,7 +80,7 @@ static bool setup_device(void) { #endif static const int one = 1; - setsockopt(device_fd, SOL_SOCKET, SO_REUSEADDR, (void *)&one, sizeof one); + setsockopt(device_fd, SOL_SOCKET, SO_REUSEADDR, (void *)&one, sizeof(one)); if(bind(device_fd, ai->ai_addr, ai->ai_addrlen)) { logger(DEBUG_ALWAYS, LOG_ERR, "Can't bind to %s %s: %s", host, port, sockstrerror(sockerrno)); @@ -92,18 +92,18 @@ static bool setup_device(void) { case AF_INET: { struct ip_mreq mreq; struct sockaddr_in in; - memcpy(&in, ai->ai_addr, sizeof in); + memcpy(&in, ai->ai_addr, sizeof(in)); mreq.imr_multiaddr.s_addr = in.sin_addr.s_addr; mreq.imr_interface.s_addr = htonl(INADDR_ANY); - if(setsockopt(device_fd, IPPROTO_IP, IP_ADD_MEMBERSHIP, (void *)&mreq, sizeof mreq)) { + if(setsockopt(device_fd, IPPROTO_IP, IP_ADD_MEMBERSHIP, (void *)&mreq, sizeof(mreq))) { logger(DEBUG_ALWAYS, LOG_ERR, "Cannot join multicast group %s %s: %s", host, port, sockstrerror(sockerrno)); goto error; } #ifdef IP_MULTICAST_LOOP - setsockopt(device_fd, IPPROTO_IP, IP_MULTICAST_LOOP, (const void *)&one, sizeof one); + setsockopt(device_fd, IPPROTO_IP, IP_MULTICAST_LOOP, (const void *)&one, sizeof(one)); #endif #ifdef IP_MULTICAST_TTL - setsockopt(device_fd, IPPROTO_IP, IP_MULTICAST_TTL, (void *)&ttl, sizeof ttl); + setsockopt(device_fd, IPPROTO_IP, IP_MULTICAST_TTL, (void *)&ttl, sizeof(ttl)); #endif } break; #endif @@ -112,18 +112,18 @@ static bool setup_device(void) { case AF_INET6: { struct ipv6_mreq mreq; struct sockaddr_in6 in6; - memcpy(&in6, ai->ai_addr, sizeof in6); - memcpy(&mreq.ipv6mr_multiaddr, &in6.sin6_addr, sizeof mreq.ipv6mr_multiaddr); + memcpy(&in6, ai->ai_addr, sizeof(in6)); + memcpy(&mreq.ipv6mr_multiaddr, &in6.sin6_addr, sizeof(mreq.ipv6mr_multiaddr)); mreq.ipv6mr_interface = in6.sin6_scope_id; - if(setsockopt(device_fd, IPPROTO_IPV6, IPV6_JOIN_GROUP, (void *)&mreq, sizeof mreq)) { + if(setsockopt(device_fd, IPPROTO_IPV6, IPV6_JOIN_GROUP, (void *)&mreq, sizeof(mreq))) { logger(DEBUG_ALWAYS, LOG_ERR, "Cannot join multicast group %s %s: %s", host, port, sockstrerror(sockerrno)); goto error; } #ifdef IPV6_MULTICAST_LOOP - setsockopt(device_fd, IPPROTO_IPV6, IPV6_MULTICAST_LOOP, (const void *)&one, sizeof one); + setsockopt(device_fd, IPPROTO_IPV6, IPV6_MULTICAST_LOOP, (const void *)&one, sizeof(one)); #endif #ifdef IPV6_MULTICAST_HOPS - setsockopt(device_fd, IPPROTO_IPV6, IPV6_MULTICAST_HOPS, (void *)&ttl, sizeof ttl); + setsockopt(device_fd, IPPROTO_IPV6, IPV6_MULTICAST_HOPS, (void *)&ttl, sizeof(ttl)); #endif } break; #endif @@ -168,7 +168,7 @@ static bool read_packet(vpn_packet_t *packet) { return false; } - if(!memcmp(&ignore_src, DATA(packet) + 6, sizeof ignore_src)) { + if(!memcmp(&ignore_src, DATA(packet) + 6, sizeof(ignore_src))) { logger(DEBUG_SCARY_THINGS, LOG_DEBUG, "Ignoring loopback packet of %d bytes from %s", lenin, device_info); return false; } @@ -191,7 +191,7 @@ static bool write_packet(vpn_packet_t *packet) { return false; } - memcpy(&ignore_src, DATA(packet) + 6, sizeof ignore_src); + memcpy(&ignore_src, DATA(packet) + 6, sizeof(ignore_src)); return true; } diff --git a/src/names.c b/src/names.c index 0cae28af..95aad2ba 100644 --- a/src/names.c +++ b/src/names.c @@ -42,7 +42,7 @@ void make_names(bool daemon) { #ifdef HAVE_MINGW HKEY key; char installdir[1024] = ""; - DWORD len = sizeof installdir; + DWORD len = sizeof(installdir); #endif confbase_given = confbase; @@ -93,9 +93,9 @@ void make_names(bool daemon) { fallback = true; } else { char fname[PATH_MAX]; - snprintf(fname, sizeof fname, LOCALSTATEDIR SLASH "run" SLASH "%s.pid", identname); + snprintf(fname, sizeof(fname), LOCALSTATEDIR SLASH "run" SLASH "%s.pid", identname); if(access(fname, R_OK)) { - snprintf(fname, sizeof fname, "%s" SLASH "pid", confbase); + snprintf(fname, sizeof(fname), "%s" SLASH "pid", confbase); if(!access(fname, R_OK)) fallback = true; } diff --git a/src/net.c b/src/net.c index 1cb467d4..887447bf 100644 --- a/src/net.c +++ b/src/net.c @@ -293,7 +293,7 @@ int reload_configuration(void) { read_config_options(config_tree, NULL); - snprintf(fname, sizeof fname, "%s" SLASH "hosts" SLASH "%s", confbase, myself->name); + snprintf(fname, sizeof(fname), "%s" SLASH "hosts" SLASH "%s", confbase, myself->name); read_config_file(config_tree, fname); /* Parse some options that are allowed to be changed while tinc is running */ @@ -376,7 +376,7 @@ int reload_configuration(void) { if(c->status.control) continue; - snprintf(fname, sizeof fname, "%s" SLASH "hosts" SLASH "%s", confbase, c->name); + snprintf(fname, sizeof(fname), "%s" SLASH "hosts" SLASH "%s", confbase, c->name); struct stat s; if(stat(fname, &s) || s.st_mtime > last_config_check) { logger(DEBUG_CONNECTIONS, LOG_INFO, "Host config file of %s has been changed", c->name); diff --git a/src/net_packet.c b/src/net_packet.c index 5d559bd8..2d430bc0 100644 --- a/src/net_packet.c +++ b/src/net_packet.c @@ -347,9 +347,9 @@ static bool receive_udppacket(node_t *n, vpn_packet_t *inpkt) { /* Check the sequence number */ seqno_t seqno; - memcpy(&seqno, SEQNO(inpkt), sizeof seqno); + memcpy(&seqno, SEQNO(inpkt), sizeof(seqno)); seqno = ntohl(seqno); - inpkt->len -= sizeof seqno; + inpkt->len -= sizeof(seqno); if(replaywin) { if(seqno != n->received_seqno + 1) { @@ -421,7 +421,7 @@ void receive_tcppacket(connection_t *c, const char *buffer, int len) { vpn_packet_t outpkt; outpkt.offset = DEFAULT_PACKET_OFFSET; - if(len > sizeof outpkt.data - outpkt.offset) + if(len > sizeof(outpkt.data) - outpkt.offset) return; outpkt.len = len; @@ -677,8 +677,8 @@ static void send_udppacket(node_t *n, vpn_packet_t *origpkt) { /* Add sequence number */ seqno_t seqno = htonl(++(n->sent_seqno)); - memcpy(SEQNO(inpkt), &seqno, sizeof seqno); - inpkt->len += sizeof seqno; + memcpy(SEQNO(inpkt), &seqno, sizeof(seqno)); + inpkt->len += sizeof(seqno); /* Encrypt the packet */ @@ -722,14 +722,14 @@ static void send_udppacket(node_t *n, vpn_packet_t *origpkt) { #if defined(IPPROTO_IP) && defined(IP_TOS) case AF_INET: logger(DEBUG_TRAFFIC, LOG_DEBUG, "Setting IPv4 outgoing packet priority to %d", origpriority); - if(setsockopt(listen_socket[sock].udp.fd, IPPROTO_IP, IP_TOS, (void *)&origpriority, sizeof origpriority)) /* SO_PRIORITY doesn't seem to work */ + if(setsockopt(listen_socket[sock].udp.fd, IPPROTO_IP, IP_TOS, (void *)&origpriority, sizeof(origpriority))) /* SO_PRIORITY doesn't seem to work */ logger(DEBUG_ALWAYS, LOG_ERR, "System call `%s' failed: %s", "setsockopt", sockstrerror(sockerrno)); break; #endif #if defined(IPPROTO_IPV6) & defined(IPV6_TCLASS) case AF_INET6: logger(DEBUG_TRAFFIC, LOG_DEBUG, "Setting IPv6 outgoing packet priority to %d", origpriority); - if(setsockopt(listen_socket[sock].udp.fd, IPPROTO_IPV6, IPV6_TCLASS, (void *)&origpriority, sizeof origpriority)) /* SO_PRIORITY doesn't seem to work */ + if(setsockopt(listen_socket[sock].udp.fd, IPPROTO_IPV6, IPV6_TCLASS, (void *)&origpriority, sizeof(origpriority))) /* SO_PRIORITY doesn't seem to work */ logger(DEBUG_ALWAYS, LOG_ERR, "System call `%s' failed: %s", "setsockopt", sockstrerror(sockerrno)); break; #endif @@ -764,12 +764,12 @@ bool send_sptps_data(node_t *to, node_t *from, int type, const void *data, size_ if(type == SPTPS_HANDSHAKE || tcponly || (!direct && !relay_supported) || (type != PKT_PROBE && (len - SPTPS_DATAGRAM_OVERHEAD) > relay->minmtu)) { if(type != SPTPS_HANDSHAKE && (to->nexthop->connection->options >> 24) >= 7) { - char buf[len + sizeof to->id + sizeof from->id]; char* buf_ptr = buf; - memcpy(buf_ptr, &to->id, sizeof to->id); buf_ptr += sizeof to->id; - memcpy(buf_ptr, &from->id, sizeof from->id); buf_ptr += sizeof from->id; + char buf[len + sizeof(to->id) + sizeof from->id]; char* buf_ptr = buf; + memcpy(buf_ptr, &to->id, sizeof(to->id)); buf_ptr += sizeof to->id; + memcpy(buf_ptr, &from->id, sizeof(from->id)); buf_ptr += sizeof from->id; memcpy(buf_ptr, data, len); logger(DEBUG_TRAFFIC, LOG_INFO, "Sending packet from %s (%s) to %s (%s) via %s (%s) (TCP)", from->name, from->hostname, to->name, to->hostname, to->nexthop->name, to->nexthop->hostname); - return send_sptps_tcppacket(to->nexthop->connection, buf, sizeof buf); + return send_sptps_tcppacket(to->nexthop->connection, buf, sizeof(buf)); } char buf[len * 4 / 3 + 5]; @@ -786,17 +786,17 @@ bool send_sptps_data(node_t *to, node_t *from, int type, const void *data, size_ } size_t overhead = 0; - if(relay_supported) overhead += sizeof to->id + sizeof from->id; + if(relay_supported) overhead += sizeof(to->id) + sizeof from->id; char buf[len + overhead]; char* buf_ptr = buf; if(relay_supported) { if(direct) { /* Inform the recipient that this packet was sent directly. */ node_id_t nullid = {}; - memcpy(buf_ptr, &nullid, sizeof nullid); buf_ptr += sizeof nullid; + memcpy(buf_ptr, &nullid, sizeof(nullid)); buf_ptr += sizeof nullid; } else { - memcpy(buf_ptr, &to->id, sizeof to->id); buf_ptr += sizeof to->id; + memcpy(buf_ptr, &to->id, sizeof(to->id)); buf_ptr += sizeof to->id; } - memcpy(buf_ptr, &from->id, sizeof from->id); buf_ptr += sizeof from->id; + memcpy(buf_ptr, &from->id, sizeof(from->id)); buf_ptr += sizeof from->id; } /* TODO: if this copy turns out to be a performance concern, change sptps_send_record() to add some "pre-padding" to the buffer and use that instead */ @@ -1018,7 +1018,7 @@ static length_t choose_initial_maxmtu(node_t *n) { } int ip_mtu; - socklen_t ip_mtu_len = sizeof ip_mtu; + socklen_t ip_mtu_len = sizeof(ip_mtu); if(getsockopt(sock, IPPROTO_IP, IP_MTU, &ip_mtu, &ip_mtu_len)) { logger(DEBUG_TRAFFIC, LOG_ERR, "getsockopt(IP_MTU) on %s (%s) failed: %s", n->name, n->hostname, sockstrerror(sockerrno)); close(sock); @@ -1422,7 +1422,7 @@ static void handle_incoming_vpn_packet(listen_socket_t *ls, vpn_packet_t *pkt, s // It might be from a 1.1 node, which might have a source ID in the packet. pkt->offset = 2 * sizeof(node_id_t); from = lookup_node_id(SRCID(pkt)); - if(from && !memcmp(DSTID(pkt), &nullid, sizeof nullid) && from->status.sptps) { + if(from && !memcmp(DSTID(pkt), &nullid, sizeof(nullid)) && from->status.sptps) { if(sptps_verify_datagram(&from->sptps, DATA(pkt), pkt->len - 2 * sizeof(node_id_t))) n = from; else @@ -1454,7 +1454,7 @@ skip_harder: pkt->len -= pkt->offset; } - if(!memcmp(DSTID(pkt), &nullid, sizeof nullid) || !relay_enabled) { + if(!memcmp(DSTID(pkt), &nullid, sizeof(nullid)) || !relay_enabled) { direct = true; from = n; to = myself; @@ -1530,7 +1530,7 @@ void handle_incoming_vpn_data(void *data, int flags) { msg[i].msg_hdr = (struct msghdr){ .msg_name = &addr[i].sa, - .msg_namelen = sizeof addr[i], + .msg_namelen = sizeof(addr)[i], .msg_iov = &iov[i], .msg_iovlen = 1, }; @@ -1553,7 +1553,7 @@ void handle_incoming_vpn_data(void *data, int flags) { #else vpn_packet_t pkt; sockaddr_t addr = {}; - socklen_t addrlen = sizeof addr; + socklen_t addrlen = sizeof(addr); pkt.offset = 0; int len = recvfrom(ls->udp.fd, (void *)DATA(&pkt), MAXSIZE, 0, &addr.sa, &addrlen); diff --git a/src/net_setup.c b/src/net_setup.c index e164214f..85553be4 100644 --- a/src/net_setup.c +++ b/src/net_setup.c @@ -236,7 +236,7 @@ static bool read_invitation_key(void) { invitation_key = NULL; } - snprintf(fname, sizeof fname, "%s" SLASH "invitations" SLASH "ed25519_key.priv", confbase); + snprintf(fname, sizeof(fname), "%s" SLASH "invitations" SLASH "ed25519_key.priv", confbase); fp = fopen(fname, "r"); @@ -328,7 +328,7 @@ void load_all_nodes(void) { struct dirent *ent; char dname[PATH_MAX]; - snprintf(dname, sizeof dname, "%s" SLASH "hosts", confbase); + snprintf(dname, sizeof(dname), "%s" SLASH "hosts", confbase); dir = opendir(dname); if(!dir) { logger(DEBUG_ALWAYS, LOG_ERR, "Could not open %s: %s", dname, strerror(errno)); @@ -957,7 +957,7 @@ static bool setup_myself(void) { } for(int i = 0; i < listen_sockets; i++) { - salen = sizeof sa; + salen = sizeof(sa); if(getsockname(i + 3, &sa.sa, &salen) < 0) { logger(DEBUG_ALWAYS, LOG_ERR, "Could not get address of listen fd %d: %s", i + 3, sockstrerror(sockerrno)); return false; @@ -1014,7 +1014,7 @@ static bool setup_myself(void) { if(!port_specified || atoi(myport) == 0) { sockaddr_t sa; - socklen_t salen = sizeof sa; + socklen_t salen = sizeof(sa); if(!getsockname(listen_socket[0].udp.fd, &sa.sa, &salen)) { free(myport); sockaddr2str(&sa, NULL, &myport); diff --git a/src/net_socket.c b/src/net_socket.c index ac6b8402..46dbdf6c 100644 --- a/src/net_socket.c +++ b/src/net_socket.c @@ -70,17 +70,17 @@ static void configure_tcp(connection_t *c) { #if defined(IPPROTO_TCP) && defined(TCP_NODELAY) option = 1; - setsockopt(c->socket, IPPROTO_TCP, TCP_NODELAY, (void *)&option, sizeof option); + setsockopt(c->socket, IPPROTO_TCP, TCP_NODELAY, (void *)&option, sizeof(option)); #endif #if defined(IPPROTO_IP) && defined(IP_TOS) && defined(IPTOS_LOWDELAY) option = IPTOS_LOWDELAY; - setsockopt(c->socket, IPPROTO_IP, IP_TOS, (void *)&option, sizeof option); + setsockopt(c->socket, IPPROTO_IP, IP_TOS, (void *)&option, sizeof(option)); #endif #if defined(IPPROTO_IPV6) && defined(IPV6_TCLASS) && defined(IPTOS_LOWDELAY) option = IPTOS_LOWDELAY; - setsockopt(c->socket, IPPROTO_IPV6, IPV6_TCLASS, (void *)&option, sizeof option); + setsockopt(c->socket, IPPROTO_IPV6, IPV6_TCLASS, (void *)&option, sizeof(option)); #endif } @@ -161,11 +161,11 @@ int setup_listen_socket(const sockaddr_t *sa) { /* Optimize TCP settings */ option = 1; - setsockopt(nfd, SOL_SOCKET, SO_REUSEADDR, (void *)&option, sizeof option); + setsockopt(nfd, SOL_SOCKET, SO_REUSEADDR, (void *)&option, sizeof(option)); #if defined(IPPROTO_IPV6) && defined(IPV6_V6ONLY) if(sa->sa.sa_family == AF_INET6) - setsockopt(nfd, IPPROTO_IPV6, IPV6_V6ONLY, (void *)&option, sizeof option); + setsockopt(nfd, IPPROTO_IPV6, IPV6_V6ONLY, (void *)&option, sizeof(option)); #endif if(get_config_string @@ -173,10 +173,10 @@ int setup_listen_socket(const sockaddr_t *sa) { #if defined(SOL_SOCKET) && defined(SO_BINDTODEVICE) struct ifreq ifr; - memset(&ifr, 0, sizeof ifr); + memset(&ifr, 0, sizeof(ifr)); strncpy(ifr.ifr_ifrn.ifrn_name, iface, IFNAMSIZ); - if(setsockopt(nfd, SOL_SOCKET, SO_BINDTODEVICE, (void *)&ifr, sizeof ifr)) { + if(setsockopt(nfd, SOL_SOCKET, SO_BINDTODEVICE, (void *)&ifr, sizeof(ifr))) { closesocket(nfd); logger(DEBUG_ALWAYS, LOG_ERR, "Can't bind to interface %s: %s", iface, sockstrerror(sockerrno)); @@ -243,8 +243,8 @@ int setup_vpn_in_socket(const sockaddr_t *sa) { #endif option = 1; - setsockopt(nfd, SOL_SOCKET, SO_REUSEADDR, (void *)&option, sizeof option); - setsockopt(nfd, SOL_SOCKET, SO_BROADCAST, (void *)&option, sizeof option); + setsockopt(nfd, SOL_SOCKET, SO_REUSEADDR, (void *)&option, sizeof(option)); + setsockopt(nfd, SOL_SOCKET, SO_BROADCAST, (void *)&option, sizeof(option)); if(udp_rcvbuf && setsockopt(nfd, SOL_SOCKET, SO_RCVBUF, (void *)&udp_rcvbuf, sizeof(udp_rcvbuf))) logger(DEBUG_ALWAYS, LOG_WARNING, "Can't set UDP SO_RCVBUF to %i: %s", udp_rcvbuf, sockstrerror(sockerrno)); @@ -254,7 +254,7 @@ int setup_vpn_in_socket(const sockaddr_t *sa) { #if defined(IPPROTO_IPV6) && defined(IPV6_V6ONLY) if(sa->sa.sa_family == AF_INET6) - setsockopt(nfd, IPPROTO_IPV6, IPV6_V6ONLY, (void *)&option, sizeof option); + setsockopt(nfd, IPPROTO_IPV6, IPV6_V6ONLY, (void *)&option, sizeof(option)); #endif #if defined(IP_DONTFRAG) && !defined(IP_DONTFRAGMENT) @@ -421,7 +421,7 @@ static void handle_meta_io(void *data, int flags) { if (!socknotconn(sockerrno)) socket_error = sockerrno; else { - socklen_t len = sizeof socket_error; + socklen_t len = sizeof(socket_error); getsockopt(c->socket, SOL_SOCKET, SO_ERROR, (void *)&socket_error, &len); } if (socket_error) { @@ -532,7 +532,7 @@ begin: #if defined(IPPROTO_IPV6) && defined(IPV6_V6ONLY) int option = 1; if(c->address.sa.sa_family == AF_INET6) - setsockopt(c->socket, IPPROTO_IPV6, IPV6_V6ONLY, (void *)&option, sizeof option); + setsockopt(c->socket, IPPROTO_IPV6, IPV6_V6ONLY, (void *)&option, sizeof(option)); #endif bind_to_interface(c->socket); @@ -599,7 +599,7 @@ static struct addrinfo *get_known_addresses(node_t *n) { continue; oai = ai; - ai = xzalloc(sizeof *ai); + ai = xzalloc(sizeof(*ai)); ai->ai_family = e->reverse->address.sa.sa_family; ai->ai_socktype = SOCK_STREAM; ai->ai_protocol = IPPROTO_TCP; @@ -656,7 +656,7 @@ void handle_new_meta_connection(void *data, int flags) { connection_t *c; sockaddr_t sa; int fd; - socklen_t len = sizeof sa; + socklen_t len = sizeof(sa); fd = accept(l->tcp.fd, &sa.sa, &len); @@ -695,7 +695,7 @@ void handle_new_meta_connection(void *data, int flags) { } } - memcpy(&prev_sa, &sa, sizeof sa); + memcpy(&prev_sa, &sa, sizeof(sa)); // Check if we get many connections from different hosts @@ -753,7 +753,7 @@ void handle_new_unix_connection(void *data, int flags) { connection_t *c; sockaddr_t sa; int fd; - socklen_t len = sizeof sa; + socklen_t len = sizeof(sa); fd = accept(io->fd, &sa.sa, &len); @@ -841,7 +841,7 @@ void try_outgoing_connections(void) { } if(!found) { - outgoing_t *outgoing = xzalloc(sizeof *outgoing); + outgoing_t *outgoing = xzalloc(sizeof(*outgoing)); outgoing->name = name; list_insert_tail(outgoing_list, outgoing); setup_outgoing_connection(outgoing); diff --git a/src/netutl.c b/src/netutl.c index a9ad17ce..69714eae 100644 --- a/src/netutl.c +++ b/src/netutl.c @@ -97,7 +97,7 @@ void sockaddr2str(const sockaddr_t *sa, char **addrstr, char **portstr) { return; } - err = getnameinfo(&sa->sa, SALEN(sa->sa), address, sizeof address, port, sizeof port, NI_NUMERICHOST | NI_NUMERICSERV); + err = getnameinfo(&sa->sa, SALEN(sa->sa), address, sizeof(address), port, sizeof port, NI_NUMERICHOST | NI_NUMERICSERV); if(err) { logger(DEBUG_ALWAYS, LOG_ERR, "Error while translating addresses: %s", err == EAI_SYSTEM ? strerror(errno) : gai_strerror(err)); @@ -129,7 +129,7 @@ char *sockaddr2hostname(const sockaddr_t *sa) { return str; } - err = getnameinfo(&sa->sa, SALEN(sa->sa), address, sizeof address, port, sizeof port, + err = getnameinfo(&sa->sa, SALEN(sa->sa), address, sizeof(address), port, sizeof port, hostnames ? 0 : (NI_NUMERICHOST | NI_NUMERICSERV)); if(err) { logger(DEBUG_ALWAYS, LOG_ERR, "Error while looking up hostname: %s", err == EAI_SYSTEM ? strerror(errno) : gai_strerror(err)); @@ -189,20 +189,20 @@ int sockaddrcmp(const sockaddr_t *a, const sockaddr_t *b) { return strcmp(a->unknown.port, b->unknown.port); case AF_INET: - result = memcmp(&a->in.sin_addr, &b->in.sin_addr, sizeof a->in.sin_addr); + result = memcmp(&a->in.sin_addr, &b->in.sin_addr, sizeof(a->in.sin_addr)); if(result) return result; - return memcmp(&a->in.sin_port, &b->in.sin_port, sizeof a->in.sin_port); + return memcmp(&a->in.sin_port, &b->in.sin_port, sizeof(a->in.sin_port)); case AF_INET6: - result = memcmp(&a->in6.sin6_addr, &b->in6.sin6_addr, sizeof a->in6.sin6_addr); + result = memcmp(&a->in6.sin6_addr, &b->in6.sin6_addr, sizeof(a->in6.sin6_addr)); if(result) return result; - return memcmp(&a->in6.sin6_port, &b->in6.sin6_port, sizeof a->in6.sin6_port); + return memcmp(&a->in6.sin6_port, &b->in6.sin6_port, sizeof(a->in6.sin6_port)); default: logger(DEBUG_ALWAYS, LOG_ERR, "sockaddrcmp() was called with unknown address family %d, exitting!", diff --git a/src/node.c b/src/node.c index b17e6929..b4ddecb8 100644 --- a/src/node.c +++ b/src/node.c @@ -66,7 +66,7 @@ void exit_nodes(void) { } node_t *new_node(void) { - node_t *n = xzalloc(sizeof *n); + node_t *n = xzalloc(sizeof(*n)); if(replaywin) n->late = xzalloc(replaywin); n->subnet_tree = new_subnet_tree(); @@ -113,7 +113,7 @@ void free_node(node_t *n) { void node_add(node_t *n) { unsigned char buf[64]; sha512(n->name, strlen(n->name),buf); - memcpy(&n->id, buf, sizeof n->id); + memcpy(&n->id, buf, sizeof(n->id)); splay_insert(node_tree, n); splay_insert(node_id_tree, n); @@ -184,10 +184,10 @@ void update_node_udp(node_t *n, const sockaddr_t *sa) { bool dump_nodes(connection_t *c) { for splay_each(node_t, n, node_tree) { - char id[2 * sizeof n->id + 1]; - for (size_t c = 0; c < sizeof n->id; ++c) + char id[2 * sizeof(n->id) + 1]; + for (size_t c = 0; c < sizeof(n->id); ++c) snprintf(id + 2 * c, 3, "%02x", n->id.x[c]); - id[sizeof id - 1] = 0; + 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", CONTROL, REQ_DUMP_NODES, n->name, id, n->hostname ?: "unknown port unknown", #ifdef DISABLE_LEGACY @@ -195,7 +195,7 @@ bool dump_nodes(connection_t *c) { #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->outcompression, n->options, bitfield_to_int(&n->status, sizeof(n->status)), n->nexthop ? n->nexthop->name : "-", n->via ? n->via->name ?: "-" : "-", n->distance, n->mtu, n->minmtu, n->maxmtu, (long)n->last_state_change); } diff --git a/src/nolegacy/prf.c b/src/nolegacy/prf.c index 55c9923d..1937f675 100644 --- a/src/nolegacy/prf.c +++ b/src/nolegacy/prf.c @@ -60,7 +60,7 @@ static bool hmac_sha512(const char *key, size_t keylen, const char *msg, size_t // opad memxor(tmp, 0x36 ^ 0x5c, blklen); - if(sha512(tmp, sizeof tmp, out) != 0) + if(sha512(tmp, sizeof(tmp), out) != 0) return false; return true; @@ -84,17 +84,17 @@ bool prf(const char *secret, size_t secretlen, char *seed, size_t seedlen, char while(outlen > 0) { /* Inner HMAC */ - if(!hmac_sha512(secret, secretlen, data, sizeof data, data)) + if(!hmac_sha512(secret, secretlen, data, sizeof(data), data)) return false; /* Outer HMAC */ if(outlen >= mdlen) { - if(!hmac_sha512(secret, secretlen, data, sizeof data, out)) + if(!hmac_sha512(secret, secretlen, data, sizeof(data), out)) return false; out += mdlen; outlen -= mdlen; } else { - if(!hmac_sha512(secret, secretlen, data, sizeof data, hash)) + if(!hmac_sha512(secret, secretlen, data, sizeof(data), hash)) return false; memcpy(out, hash, outlen); out += outlen; diff --git a/src/openssl/cipher.c b/src/openssl/cipher.c index 98033c5e..d5cafa41 100644 --- a/src/openssl/cipher.c +++ b/src/openssl/cipher.c @@ -33,7 +33,7 @@ struct cipher { }; static cipher_t *cipher_open(const EVP_CIPHER *evp_cipher) { - cipher_t *cipher = xzalloc(sizeof *cipher); + cipher_t *cipher = xzalloc(sizeof(*cipher)); cipher->cipher = evp_cipher; cipher->ctx = EVP_CIPHER_CTX_new(); if(!cipher->ctx) diff --git a/src/openssl/digest.c b/src/openssl/digest.c index 58ca167f..65df7cb6 100644 --- a/src/openssl/digest.c +++ b/src/openssl/digest.c @@ -29,7 +29,7 @@ #include "../logger.h" static digest_t *digest_open(const EVP_MD *evp_md, int maclength) { - digest_t *digest = xzalloc(sizeof *digest); + digest_t *digest = xzalloc(sizeof(*digest)); digest->digest = evp_md; int digestlen = EVP_MD_size(digest->digest); diff --git a/src/process.c b/src/process.c index 5bb7eb3d..153dc67d 100644 --- a/src/process.c +++ b/src/process.c @@ -63,22 +63,22 @@ static bool install_service(void) { } HMODULE module = GetModuleHandle(NULL); - GetModuleFileName(module, command + 1, sizeof command - 1); - command[sizeof command - 1] = 0; + GetModuleFileName(module, command + 1, sizeof(command) - 1); + command[sizeof(command) - 1] = 0; - strncat(command, "\"", sizeof command - strlen(command)); + strncat(command, "\"", sizeof(command) - strlen(command)); for(char **argp = g_argv + 1; *argp; argp++) { char *space = strchr(*argp, ' '); - strncat(command, " ", sizeof command - strlen(command)); + strncat(command, " ", sizeof(command) - strlen(command)); if(space) - strncat(command, "\"", sizeof command - strlen(command)); + strncat(command, "\"", sizeof(command) - strlen(command)); - strncat(command, *argp, sizeof command - strlen(command)); + strncat(command, *argp, sizeof(command) - strlen(command)); if(space) - strncat(command, "\"", sizeof command - strlen(command)); + strncat(command, "\"", sizeof(command) - strlen(command)); } service = CreateService(manager, identname, identname, diff --git a/src/protocol.c b/src/protocol.c index b9abccc3..79d52733 100644 --- a/src/protocol.c +++ b/src/protocol.c @@ -72,11 +72,11 @@ bool send_request(connection_t *c, const char *format, ...) { input buffer anyway */ va_start(args, format); - len = vsnprintf(request, sizeof request, format, args); - request[sizeof request - 1] = 0; + len = vsnprintf(request, sizeof(request), format, args); + request[sizeof(request) - 1] = 0; va_end(args); - if(len < 0 || len > sizeof request - 1) { + if(len < 0 || len > sizeof(request) - 1) { logger(DEBUG_ALWAYS, LOG_ERR, "Output buffer overflow while sending request to %s (%s)", c->name, c->hostname); return false; @@ -101,7 +101,7 @@ void forward_request(connection_t *from, const char *request) { char tmp[len + 1]; memcpy(tmp, request, len); tmp[len] = '\n'; - broadcast_meta(from, tmp, sizeof tmp); + broadcast_meta(from, tmp, sizeof(tmp)); } bool receive_request(connection_t *c, const char *request) { @@ -188,7 +188,7 @@ bool seen_request(const char *request) { logger(DEBUG_SCARY_THINGS, LOG_DEBUG, "Already seen request"); return true; } else { - new = xmalloc(sizeof *new); + new = xmalloc(sizeof(*new)); new->request = xstrdup(request); new->firstseen = now.tv_sec; splay_insert(past_request_tree, new); diff --git a/src/protocol_auth.c b/src/protocol_auth.c index a99e1d61..2cface21 100644 --- a/src/protocol_auth.c +++ b/src/protocol_auth.c @@ -74,9 +74,9 @@ static bool send_proxyrequest(connection_t *c) { memcpy(s4req + 4, &c->address.in.sin_addr, 4); if(proxyuser) memcpy(s4req + 8, proxyuser, strlen(proxyuser)); - s4req[sizeof s4req - 1] = 0; + s4req[sizeof(s4req) - 1] = 0; c->tcplen = 8; - return send_meta(c, s4req, sizeof s4req); + return send_meta(c, s4req, sizeof(s4req)); } case PROXY_SOCKS5: { int len = 3 + 6 + (c->address.sa.sa_family == AF_INET ? 4 : 16); @@ -123,7 +123,7 @@ static bool send_proxyrequest(connection_t *c) { } if(i > len) abort(); - return send_meta(c, s5req, sizeof s5req); + return send_meta(c, s5req, sizeof(s5req)); } case PROXY_SOCKS4A: logger(DEBUG_ALWAYS, LOG_ERR, "Proxy type not implemented yet"); @@ -163,7 +163,7 @@ static bool finalize_invitation(connection_t *c, const char *data, uint16_t len) // Create a new host config file char filename[PATH_MAX]; - snprintf(filename, sizeof filename, "%s" SLASH "hosts" SLASH "%s", confbase, c->name); + snprintf(filename, sizeof(filename), "%s" SLASH "hosts" SLASH "%s", confbase, c->name); if(!access(filename, F_OK)) { logger(DEBUG_ALWAYS, LOG_ERR, "Host config file for %s (%s) already exists!\n", c->name, c->hostname); return false; @@ -215,14 +215,14 @@ static bool receive_invitation_sptps(void *handle, uint8_t type, const void *dat char hashbuf[18 + strlen(fingerprint)]; char cookie[64]; memcpy(hashbuf, data, 18); - memcpy(hashbuf + 18, fingerprint, sizeof hashbuf - 18); - sha512(hashbuf, sizeof hashbuf, cookie); + memcpy(hashbuf + 18, fingerprint, sizeof(hashbuf) - 18); + sha512(hashbuf, sizeof(hashbuf), cookie); b64encode_urlsafe(cookie, cookie, 18); free(fingerprint); char filename[PATH_MAX], usedname[PATH_MAX]; - snprintf(filename, sizeof filename, "%s" SLASH "invitations" SLASH "%s", confbase, cookie); - snprintf(usedname, sizeof usedname, "%s" SLASH "invitations" SLASH "%s.used", confbase, cookie); + snprintf(filename, sizeof(filename), "%s" SLASH "invitations" SLASH "%s", confbase, cookie); + snprintf(usedname, sizeof(usedname), "%s" SLASH "invitations" SLASH "%s.used", confbase, cookie); // Atomically rename the invitation file if(rename(filename, usedname)) { @@ -254,7 +254,7 @@ static bool receive_invitation_sptps(void *handle, uint8_t type, const void *dat // Read the new node's Name from the file char buf[1024]; - fgets(buf, sizeof buf, f); + fgets(buf, sizeof(buf), f); if(*buf) buf[strlen(buf) - 1] = 0; @@ -279,7 +279,7 @@ static bool receive_invitation_sptps(void *handle, uint8_t type, const void *dat // Send the node the contents of the invitation file rewind(f); size_t result; - while((result = fread(buf, 1, sizeof buf, f))) + while((result = fread(buf, 1, sizeof(buf), f))) sptps_send_record(&c->sptps, 0, buf, result); sptps_send_record(&c->sptps, 1, buf, 0); fclose(f); @@ -409,11 +409,11 @@ bool id_h(connection_t *c, const char *request) { char label[25 + strlen(myself->name) + strlen(c->name)]; if(c->outgoing) - snprintf(label, sizeof label, "tinc TCP key expansion %s %s", myself->name, c->name); + snprintf(label, sizeof(label), "tinc TCP key expansion %s %s", myself->name, c->name); else - snprintf(label, sizeof label, "tinc TCP key expansion %s %s", c->name, myself->name); + snprintf(label, sizeof(label), "tinc TCP key expansion %s %s", c->name, myself->name); - return sptps_start(&c->sptps, c, c->outgoing, false, myself->connection->ecdsa, c->ecdsa, label, sizeof label, send_meta_sptps, receive_meta_sptps); + return sptps_start(&c->sptps, c, c->outgoing, false, myself->connection->ecdsa, c->ecdsa, label, sizeof(label), send_meta_sptps, receive_meta_sptps); } else { return send_metakey(c); } @@ -528,7 +528,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); + int inlen = hex2bin(hexkey, enckey, sizeof(enckey)); /* Check if the length of the meta key is all right */ @@ -622,7 +622,7 @@ bool challenge_h(connection_t *c, const char *request) { /* Convert the challenge from hexadecimal back to binary */ - int inlen = hex2bin(buffer, buffer, sizeof buffer); + int inlen = hex2bin(buffer, buffer, sizeof(buffer)); /* Check if the length of the challenge is all right */ @@ -662,7 +662,7 @@ bool chal_reply_h(connection_t *c, const char *request) { /* Convert the hash to binary format */ - int inlen = hex2bin(hishash, hishash, sizeof hishash); + int inlen = hex2bin(hishash, hishash, sizeof(hishash)); /* Check if the length of the hash is all right */ @@ -755,7 +755,7 @@ static void send_everything(connection_t *c) { char pad[MAXBUFSIZE - MAXSIZE]; } zeropkt; - memset(&zeropkt, 0, sizeof zeropkt); + memset(&zeropkt, 0, sizeof(zeropkt)); zeropkt.pkt.len = MAXBUFSIZE; send_tcppacket(c, &zeropkt.pkt); } @@ -895,7 +895,7 @@ bool ack_h(connection_t *c, const char *request) { sockaddrcpy(&c->edge->address, &c->address); sockaddr_setport(&c->edge->address, hisport); sockaddr_t local_sa; - socklen_t local_salen = sizeof local_sa; + socklen_t local_salen = sizeof(local_sa); if (getsockname(c->socket, &local_sa.sa, &local_salen) < 0) logger(DEBUG_ALWAYS, LOG_WARNING, "Could not get local socket address for connection with %s", c->name); else { diff --git a/src/protocol_key.c b/src/protocol_key.c index a18cefc9..6e31b5e8 100644 --- a/src/protocol_key.c +++ b/src/protocol_key.c @@ -110,13 +110,13 @@ bool send_req_key(node_t *to) { } char label[25 + strlen(myself->name) + strlen(to->name)]; - snprintf(label, sizeof label, "tinc UDP key expansion %s %s", myself->name, to->name); + snprintf(label, sizeof(label), "tinc UDP key expansion %s %s", myself->name, to->name); sptps_stop(&to->sptps); to->status.validkey = false; to->status.waitingforkey = true; to->last_req_key = now.tv_sec; to->incompression = myself->incompression; - return sptps_start(&to->sptps, to, true, true, myself->connection->ecdsa, to->ecdsa, label, sizeof label, send_initial_sptps_data, receive_sptps_record); + return sptps_start(&to->sptps, to, true, true, myself->connection->ecdsa, to->ecdsa, label, sizeof(label), send_initial_sptps_data, receive_sptps_record); } return send_request(to->nexthop->connection, "%d %s %s", REQ_KEY, myself->name, to->name); @@ -219,12 +219,12 @@ static bool req_key_ext_h(connection_t *c, const char *request, node_t *from, no } char label[25 + strlen(from->name) + strlen(myself->name)]; - snprintf(label, sizeof label, "tinc UDP key expansion %s %s", from->name, myself->name); + snprintf(label, sizeof(label), "tinc UDP key expansion %s %s", from->name, myself->name); sptps_stop(&from->sptps); from->status.validkey = false; from->status.waitingforkey = true; from->last_req_key = now.tv_sec; - sptps_start(&from->sptps, from, false, true, myself->connection->ecdsa, from->ecdsa, label, sizeof label, send_sptps_data_myself, receive_sptps_record); + sptps_start(&from->sptps, from, false, true, myself->connection->ecdsa, from->ecdsa, label, sizeof(label), send_sptps_data_myself, receive_sptps_record); sptps_receive_data(&from->sptps, buf, len); send_mtu_info(myself, from, MTU); return true; @@ -489,7 +489,7 @@ bool ans_key_h(connection_t *c, const char *request) { /* Process key */ - int keylen = hex2bin(key, key, sizeof key); + int 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_subnet.c b/src/protocol_subnet.c index 06dafbc7..bc13c219 100644 --- a/src/protocol_subnet.c +++ b/src/protocol_subnet.c @@ -35,7 +35,7 @@ bool send_add_subnet(connection_t *c, const subnet_t *subnet) { char netstr[MAXNETSTR]; - if(!net2str(netstr, sizeof netstr, subnet)) + if(!net2str(netstr, sizeof(netstr), subnet)) return false; return send_request(c, "%d %x %s %s", ADD_SUBNET, rand(), subnet->owner->name, netstr); @@ -145,7 +145,7 @@ bool add_subnet_h(connection_t *c, const char *request) { bool send_del_subnet(connection_t *c, const subnet_t *s) { char netstr[MAXNETSTR]; - if(!net2str(netstr, sizeof netstr, s)) + if(!net2str(netstr, sizeof(netstr), s)) return false; return send_request(c, "%d %x %s %s", DEL_SUBNET, rand(), s->owner->name, netstr); diff --git a/src/raw_socket_device.c b/src/raw_socket_device.c index eb38be26..18fbdde0 100644 --- a/src/raw_socket_device.c +++ b/src/raw_socket_device.c @@ -53,7 +53,7 @@ static bool setup_device(void) { return false; } - memset(&ifr, 0, sizeof ifr); + memset(&ifr, 0, sizeof(ifr)); #ifdef FD_CLOEXEC fcntl(device_fd, F_SETFD, FD_CLOEXEC); @@ -67,12 +67,12 @@ static bool setup_device(void) { return false; } - memset(&sa, '0', sizeof sa); + memset(&sa, '0', sizeof(sa)); sa.sll_family = AF_PACKET; sa.sll_protocol = htons(ETH_P_ALL); sa.sll_ifindex = ifr.ifr_ifindex; - if(bind(device_fd, (struct sockaddr *) &sa, (socklen_t) sizeof sa)) { + if(bind(device_fd, (struct sockaddr *) &sa, (socklen_t) sizeof(sa))) { logger(DEBUG_ALWAYS, LOG_ERR, "Could not bind %s to %s: %s", device, iface, strerror(errno)); return false; } diff --git a/src/route.c b/src/route.c index 7ae49607..05dc4f4b 100644 --- a/src/route.c +++ b/src/route.c @@ -107,9 +107,9 @@ static bool checklength(node_t *source, vpn_packet_t *packet, length_t length) { static void swap_mac_addresses(vpn_packet_t *packet) { mac_t tmp; - memcpy(&tmp, &DATA(packet)[0], sizeof tmp); - memcpy(&DATA(packet)[0], &DATA(packet)[6], sizeof tmp); - memcpy(&DATA(packet)[6], &tmp, sizeof tmp); + memcpy(&tmp, &DATA(packet)[0], sizeof(tmp)); + memcpy(&DATA(packet)[0], &DATA(packet)[6], sizeof(tmp)); + memcpy(&DATA(packet)[6], &tmp, sizeof(tmp)); } /* RFC 792 */ @@ -291,7 +291,7 @@ static void route_ipv6_unreachable(node_t *source, vpn_packet_t *packet, length_ /* Generate checksum */ - checksum = inet_checksum(&pseudo, sizeof pseudo, ~0); + checksum = inet_checksum(&pseudo, sizeof(pseudo), ~0); checksum = inet_checksum(&icmp6, icmp6_size, checksum); checksum = inet_checksum(DATA(packet) + ether_size + ip6_size + icmp6_size, ntohl(pseudo.length) - icmp6_size, checksum); @@ -447,7 +447,7 @@ static void age_subnets(void *data) { if(s->expires && s->expires < now.tv_sec) { if(debug_level >= DEBUG_TRAFFIC) { char netstr[MAXNETSTR]; - if(net2str(netstr, sizeof netstr, s)) + if(net2str(netstr, sizeof(netstr), s)) logger(DEBUG_TRAFFIC, LOG_INFO, "Subnet %s expired", netstr); } @@ -564,7 +564,7 @@ static void route_ipv4(node_t *source, vpn_packet_t *packet) { node_t *via; ipv4_t dest; - memcpy(&dest, &DATA(packet)[30], sizeof dest); + memcpy(&dest, &DATA(packet)[30], sizeof(dest)); subnet = lookup_subnet_ipv4(&dest); if(!subnet) { @@ -644,7 +644,7 @@ static void route_ipv6(node_t *source, vpn_packet_t *packet) { node_t *via; ipv6_t dest; - memcpy(&dest, &DATA(packet)[38], sizeof dest); + memcpy(&dest, &DATA(packet)[38], sizeof(dest)); subnet = lookup_subnet_ipv6(&dest); if(!subnet) { @@ -767,7 +767,7 @@ static void route_neighborsol(node_t *source, vpn_packet_t *packet) { /* Generate checksum */ - checksum = inet_checksum(&pseudo, sizeof pseudo, ~0); + checksum = inet_checksum(&pseudo, sizeof(pseudo), ~0); checksum = inet_checksum(&ns, ns_size, checksum); if(has_opt) { checksum = inet_checksum(&opt, opt_size, checksum); @@ -834,7 +834,7 @@ static void route_neighborsol(node_t *source, vpn_packet_t *packet) { /* Generate checksum */ - checksum = inet_checksum(&pseudo, sizeof pseudo, ~0); + checksum = inet_checksum(&pseudo, sizeof(pseudo), ~0); checksum = inet_checksum(&ns, ns_size, checksum); if(has_opt) { checksum = inet_checksum(&opt, opt_size, checksum); @@ -880,7 +880,7 @@ static void route_arp(node_t *source, vpn_packet_t *packet) { /* Check if this is a valid ARP request */ if(ntohs(arp.arp_hrd) != ARPHRD_ETHER || ntohs(arp.arp_pro) != ETH_P_IP || - arp.arp_hln != ETH_ALEN || arp.arp_pln != sizeof addr || ntohs(arp.arp_op) != ARPOP_REQUEST) { + arp.arp_hln != ETH_ALEN || arp.arp_pln != sizeof(addr) || ntohs(arp.arp_op) != ARPOP_REQUEST) { logger(DEBUG_TRAFFIC, LOG_WARNING, "Cannot route packet: received unknown type ARP request"); return; } @@ -905,9 +905,9 @@ static void route_arp(node_t *source, vpn_packet_t *packet) { if(!do_decrement_ttl(source, packet)) return; - memcpy(&addr, arp.arp_tpa, sizeof addr); /* save protocol addr */ - memcpy(arp.arp_tpa, arp.arp_spa, sizeof addr); /* swap destination and source protocol address */ - memcpy(arp.arp_spa, &addr, sizeof addr); /* ... */ + memcpy(&addr, arp.arp_tpa, sizeof(addr)); /* save protocol addr */ + memcpy(arp.arp_tpa, arp.arp_spa, sizeof(addr)); /* swap destination and source protocol address */ + memcpy(arp.arp_spa, &addr, sizeof(addr)); /* ... */ memcpy(arp.arp_tha, arp.arp_sha, ETH_ALEN); /* set target hard/proto addr */ memcpy(arp.arp_sha, DATA(packet) + ETH_ALEN, ETH_ALEN); /* set source hard/proto addr */ @@ -929,13 +929,13 @@ static void route_mac(node_t *source, vpn_packet_t *packet) { if(source == myself) { mac_t src; - memcpy(&src, &DATA(packet)[6], sizeof src); + memcpy(&src, &DATA(packet)[6], sizeof(src)); learn_mac(&src); } /* Lookup destination address */ - memcpy(&dest, &DATA(packet)[0], sizeof dest); + memcpy(&dest, &DATA(packet)[0], sizeof(dest)); subnet = lookup_subnet_mac(NULL, &dest); if(!subnet || !subnet->owner) { diff --git a/src/script.c b/src/script.c index d65551a4..80c58c04 100644 --- a/src/script.c +++ b/src/script.c @@ -69,7 +69,7 @@ static const int min_env_size = 10; int environment_add(environment_t *env, const char *format, ...) { if(env->n >= env->size) { env->size = env->n ? env->n * 2 : min_env_size; - env->entries = xrealloc(env->entries, env->size * sizeof *env->entries); + env->entries = xrealloc(env->entries, env->size * sizeof(*env->entries)); } if(format) { @@ -95,7 +95,7 @@ void environment_update(environment_t *env, int pos, const char *format, ...) { void environment_init(environment_t *env) { env->n = 0; env->size = min_env_size; - env->entries = xzalloc(env->size * sizeof *env->entries); + env->entries = xzalloc(env->size * sizeof(*env->entries)); if(netname) environment_add(env, "NETNAME=%s", netname); @@ -119,7 +119,7 @@ bool execute_script(const char *name, environment_t *env) { char scriptname[PATH_MAX]; char *command; - snprintf(scriptname, sizeof scriptname, "%s" SLASH "%s%s", confbase, name, scriptextension); + snprintf(scriptname, sizeof(scriptname), "%s" SLASH "%s%s", confbase, name, scriptextension); /* First check if there is a script */ @@ -130,7 +130,7 @@ bool execute_script(const char *name, environment_t *env) { size_t scriptlen = strlen(scriptname); char fullname[scriptlen + pathlen + 1]; char *ext = fullname + scriptlen; - strncpy(fullname, scriptname, sizeof fullname); + strncpy(fullname, scriptname, sizeof(fullname)); const char *p = pathext; bool found = false; diff --git a/src/solaris/device.c b/src/solaris/device.c index 89481c7b..7ca2e7ee 100644 --- a/src/solaris/device.c +++ b/src/solaris/device.c @@ -109,7 +109,7 @@ static bool setup_device(void) { struct strioctl strioc_ppa = { .ic_cmd = TUNNEWPPA, - .ic_len = sizeof ppa, + .ic_len = sizeof(ppa), .ic_dp = (char *)&ppa, }; @@ -151,7 +151,7 @@ static bool setup_device(void) { { /* Remove muxes just in case they are left over from a crashed tincd */ struct lifreq ifr = {}; - strncpy(ifr.lifr_name, iface, sizeof ifr.lifr_name); + strncpy(ifr.lifr_name, iface, sizeof(ifr.lifr_name)); if(ioctl(ip_fd, SIOCGLIFMUXID, &ifr) >= 0) { int muxid = ifr.lifr_arp_muxid; ioctl(ip_fd, I_PUNLINK, muxid); @@ -224,7 +224,7 @@ static bool setup_device(void) { /* Set ifname to arp */ struct strioctl strioc_if = { .ic_cmd = SIOCSLIFNAME, - .ic_len = sizeof ifr, + .ic_len = sizeof(ifr), .ic_dp = (char *)&ifr, }; @@ -280,7 +280,7 @@ static bool setup_device(void) { static void close_device(void) { if(iface) { struct lifreq ifr = {}; - strncpy(ifr.lifr_name, iface, sizeof ifr.lifr_name); + strncpy(ifr.lifr_name, iface, sizeof(ifr.lifr_name)); if(ioctl(ip_fd, SIOCGLIFMUXID, &ifr) >= 0) { int muxid = ifr.lifr_arp_muxid; ioctl(ip_fd, I_PUNLINK, muxid); diff --git a/src/sptps.c b/src/sptps.c index a1fd5e75..2d02b667 100644 --- a/src/sptps.c +++ b/src/sptps.c @@ -178,11 +178,11 @@ static bool send_sig(sptps_t *s) { memcpy(msg + 1 + 2 * (33 + keylen), s->label, s->labellen); // Sign the result. - if(!ecdsa_sign(s->mykey, msg, sizeof msg, sig)) + if(!ecdsa_sign(s->mykey, msg, sizeof(msg), sig)) return error(s, EINVAL, "Failed to sign SIG record"); // Send the SIG exchange record. - return send_record_priv(s, SPTPS_HANDSHAKE, sig, sizeof sig); + return send_record_priv(s, SPTPS_HANDSHAKE, sig, sizeof(sig)); } // Generate key material from the shared secret created from the ECDHE key exchange. @@ -284,7 +284,7 @@ static bool receive_sig(sptps_t *s, const char *data, uint16_t len) { memcpy(msg + 1 + 2 * (33 + keylen), s->label, s->labellen); // Verify signature. - if(!ecdsa_verify(s->hiskey, msg, sizeof msg, data)) + if(!ecdsa_verify(s->hiskey, msg, sizeof(msg), data)) return error(s, EIO, "Failed to verify SIG record"); // Compute shared secret. @@ -294,7 +294,7 @@ static bool receive_sig(sptps_t *s, const char *data, uint16_t len) { s->ecdh = NULL; // Generate key material from shared secret. - if(!generate_key_material(s, shared, sizeof shared)) + if(!generate_key_material(s, shared, sizeof(shared))) return false; free(s->mykex); @@ -587,7 +587,7 @@ size_t sptps_receive_data(sptps_t *s, const void *data, size_t len) { // Start a SPTPS session. bool sptps_start(sptps_t *s, void *handle, bool initiator, bool datagram, ecdsa_t *mykey, ecdsa_t *hiskey, const void *label, size_t labellen, send_data_t send_data, receive_record_t receive_record) { // Initialise struct sptps - memset(s, 0, sizeof *s); + memset(s, 0, sizeof(*s)); s->handle = handle; s->initiator = initiator; @@ -636,6 +636,6 @@ bool sptps_stop(sptps_t *s) { free(s->key); free(s->label); free(s->late); - memset(s, 0, sizeof *s); + memset(s, 0, sizeof(*s)); return true; } diff --git a/src/sptps_speed.c b/src/sptps_speed.c index bde3d697..ef97be7e 100644 --- a/src/sptps_speed.c +++ b/src/sptps_speed.c @@ -49,7 +49,7 @@ static bool receive_record(void *handle, uint8_t type, const void *data, uint16_ static void receive_data(sptps_t *sptps) { char buf[4096], *bufp = buf; int fd = *(int *)sptps->handle; - size_t len = recv(fd, buf, sizeof buf, 0); + size_t len = recv(fd, buf, sizeof(buf), 0); while(len) { size_t done = sptps_receive_data(sptps, bufp, len); if(!done) @@ -89,9 +89,9 @@ int main(int argc, char *argv[]) { crypto_init(); - randomize(buf1, sizeof buf1); - randomize(buf2, sizeof buf2); - randomize(buf3, sizeof buf3); + randomize(buf1, sizeof(buf1)); + randomize(buf2, sizeof(buf2)); + randomize(buf3, sizeof(buf3)); // Key generation diff --git a/src/sptps_test.c b/src/sptps_test.c index 8df10461..e7dcea22 100644 --- a/src/sptps_test.c +++ b/src/sptps_test.c @@ -221,7 +221,7 @@ int main(int argc, char *argv[]) { #endif struct addrinfo *ai, hint; - memset(&hint, 0, sizeof hint); + memset(&hint, 0, sizeof(hint)); hint.ai_family = addressfamily; hint.ai_socktype = datagram ? SOCK_DGRAM : SOCK_STREAM; @@ -240,7 +240,7 @@ int main(int argc, char *argv[]) { } int one = 1; - setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, (void *)&one, sizeof one); + setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, (void *)&one, sizeof(one)); if(initiator) { if(connect(sock, ai->ai_addr, ai->ai_addrlen)) { @@ -271,9 +271,9 @@ int main(int argc, char *argv[]) { char buf[65536]; struct sockaddr addr; - socklen_t addrlen = sizeof addr; + socklen_t addrlen = sizeof(addr); - if(recvfrom(sock, buf, sizeof buf, MSG_PEEK, &addr, &addrlen) <= 0) { + if(recvfrom(sock, buf, sizeof(buf), MSG_PEEK, &addr, &addrlen) <= 0) { fprintf(stderr, "Could not read from socket: %s\n", sockstrerror(sockerrno)); return 1; } @@ -331,7 +331,7 @@ int main(int argc, char *argv[]) { return 1; if(FD_ISSET(in, &fds)) { - ssize_t len = read(in, buf, sizeof buf); + ssize_t len = read(in, buf, sizeof(buf)); if(len < 0) { fprintf(stderr, "Could not read from stdin: %s\n", strerror(errno)); return 1; @@ -351,12 +351,12 @@ 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)) + if(!sptps_send_record(&s, buf[0] == '!' ? 1 : 0, buf, (len == 1 && buf[0] == '\n') ? 0 : buf[0] == '*' ? sizeof(buf) : len)) return 1; } if(FD_ISSET(sock, &fds)) { - ssize_t len = recv(sock, buf, sizeof buf, 0); + ssize_t len = recv(sock, buf, sizeof(buf), 0); if(len < 0) { fprintf(stderr, "Could not read from socket: %s\n", sockstrerror(sockerrno)); return 1; diff --git a/src/subnet.c b/src/subnet.c index 3d055b68..e72cdaa4 100644 --- a/src/subnet.c +++ b/src/subnet.c @@ -126,7 +126,7 @@ subnet_t *lookup_subnet_mac(const node_t *owner, const mac_t *address) { if(!p || p->type != SUBNET_MAC) continue; - if(!memcmp(address, &p->net.mac.address, sizeof *address)) { + if(!memcmp(address, &p->net.mac.address, sizeof(*address))) { r = p; if(!p->owner || p->owner->status.reachable) break; @@ -225,7 +225,7 @@ void subnet_update(node_t *owner, subnet_t *subnet, bool up) { if(!subnet) { for splay_each(subnet_t, subnet, owner->subnet_tree) { - if(!net2str(netstr, sizeof netstr, subnet)) + if(!net2str(netstr, sizeof(netstr), subnet)) continue; // Strip the weight from the subnet, and put it in its own environment variable @@ -242,7 +242,7 @@ void subnet_update(node_t *owner, subnet_t *subnet, bool up) { execute_script(name, &env); } } else { - if(net2str(netstr, sizeof netstr, subnet)) { + if(net2str(netstr, sizeof(netstr), subnet)) { // Strip the weight from the subnet, and put it in its own environment variable char *weight = strchr(netstr, '#'); if(weight) @@ -265,7 +265,7 @@ bool dump_subnets(connection_t *c) { for splay_each(subnet_t, subnet, subnet_tree) { char netstr[MAXNETSTR]; - if(!net2str(netstr, sizeof netstr, subnet)) + if(!net2str(netstr, sizeof(netstr), subnet)) continue; send_request(c, "%d %d %s %s", diff --git a/src/subnet_parse.c b/src/subnet_parse.c index c5f6976f..ca17dcee 100644 --- a/src/subnet_parse.c +++ b/src/subnet_parse.c @@ -103,7 +103,7 @@ bool maskcheck(const void *va, int masklen, int len) { static int subnet_compare_mac(const subnet_t *a, const subnet_t *b) { int result; - result = memcmp(&a->net.mac.address, &b->net.mac.address, sizeof a->net.mac.address); + result = memcmp(&a->net.mac.address, &b->net.mac.address, sizeof(a->net.mac.address)); if(result) return result; @@ -186,7 +186,7 @@ int subnet_compare(const subnet_t *a, const subnet_t *b) { bool str2net(subnet_t *subnet, const char *subnetstr) { char str[1024]; strncpy(str, subnetstr, sizeof(str)); - str[sizeof str - 1] = 0; + str[sizeof(str) - 1] = 0; int consumed; int weight = DEFAULT_WEIGHT; @@ -256,7 +256,7 @@ bool str2net(subnet_t *subnet, const char *subnetstr) { for (int i = 0; i < 4; i++) if (x[i] > 255) return false; - snprintf(last_colon, sizeof str - (last_colon - str), ":%02x%02x:%02x%02x", x[0], x[1], x[2], x[3]); + snprintf(last_colon, sizeof(str) - (last_colon - str), ":%02x%02x:%02x%02x", x[0], x[1], x[2], x[3]); } char* double_colon = strstr(str, "::"); diff --git a/src/tincctl.c b/src/tincctl.c index 766b769e..5dd6410c 100644 --- a/src/tincctl.c +++ b/src/tincctl.c @@ -264,13 +264,13 @@ static void disable_old_keys(const char *filename, const char *what) { if(!r) return; - snprintf(tmpfile, sizeof tmpfile, "%s.tmp", filename); + snprintf(tmpfile, sizeof(tmpfile), "%s.tmp", filename); struct stat st = {.st_mode = 0600}; fstat(fileno(r), &st); w = fopenmask(tmpfile, "w", st.st_mode); - while(fgets(buf, sizeof buf, r)) { + while(fgets(buf, sizeof(buf), r)) { if(!block && !strncmp(buf, "-----BEGIN ", 11)) { if((strstr(buf, " ED25519 ") && strstr(what, "Ed25519")) || (strstr(buf, " RSA ") && strstr(what, "RSA"))) { disabled = true; @@ -313,7 +313,7 @@ static void disable_old_keys(const char *filename, const char *what) { #ifdef HAVE_MINGW // We cannot atomically replace files on Windows. char bakfile[PATH_MAX] = ""; - snprintf(bakfile, sizeof bakfile, "%s.bak", filename); + snprintf(bakfile, sizeof(bakfile), "%s.bak", filename); if(rename(filename, bakfile) || rename(tmpfile, filename)) { rename(bakfile, filename); #else @@ -342,7 +342,7 @@ static FILE *ask_and_open(const char *filename, const char *what, const char *mo /* Ask for a file and/or directory name. */ fprintf(stderr, "Please enter a file to save %s to [%s]: ", what, filename); - if(fgets(buf, sizeof buf, stdin) == NULL) { + if(fgets(buf, sizeof(buf), stdin) == NULL) { fprintf(stderr, "Error while reading stdin: %s\n", strerror(errno)); return NULL; } @@ -361,8 +361,8 @@ static FILE *ask_and_open(const char *filename, const char *what, const char *mo if(filename[0] != '/') { #endif /* The directory is a relative path or a filename. */ - getcwd(directory, sizeof directory); - snprintf(buf2, sizeof buf2, "%s" SLASH "%s", directory, filename); + getcwd(directory, sizeof(directory)); + snprintf(buf2, sizeof(buf2), "%s" SLASH "%s", directory, filename); filename = buf2; } @@ -397,7 +397,7 @@ static bool ed25519_keygen(bool ask) { } else fprintf(stderr, "Done.\n"); - snprintf(fname, sizeof fname, "%s" SLASH "ed25519_key.priv", confbase); + snprintf(fname, sizeof(fname), "%s" SLASH "ed25519_key.priv", confbase); f = ask_and_open(fname, "private Ed25519 key", "a", ask, 0600); if(!f) @@ -411,9 +411,9 @@ static bool ed25519_keygen(bool ask) { fclose(f); if(name) - snprintf(fname, sizeof fname, "%s" SLASH "hosts" SLASH "%s", confbase, name); + snprintf(fname, sizeof(fname), "%s" SLASH "hosts" SLASH "%s", confbase, name); else - snprintf(fname, sizeof fname, "%s" SLASH "ed25519_key.pub", confbase); + snprintf(fname, sizeof(fname), "%s" SLASH "ed25519_key.pub", confbase); f = ask_and_open(fname, "public Ed25519 key", "a", ask, 0666); @@ -465,7 +465,7 @@ static bool rsa_keygen(int bits, bool ask) { } else fprintf(stderr, "Done.\n"); - snprintf(fname, sizeof fname, "%s" SLASH "rsa_key.priv", confbase); + snprintf(fname, sizeof(fname), "%s" SLASH "rsa_key.priv", confbase); f = ask_and_open(fname, "private RSA key", "a", ask, 0600); if(!f) @@ -479,9 +479,9 @@ static bool rsa_keygen(int bits, bool ask) { fclose(f); if(name) - snprintf(fname, sizeof fname, "%s" SLASH "hosts" SLASH "%s", confbase, name); + snprintf(fname, sizeof(fname), "%s" SLASH "hosts" SLASH "%s", confbase, name); else - snprintf(fname, sizeof fname, "%s" SLASH "rsa_key.pub", confbase); + snprintf(fname, sizeof(fname), "%s" SLASH "rsa_key.pub", confbase); f = ask_and_open(fname, "public RSA key", "a", ask, 0666); @@ -516,7 +516,7 @@ bool recvline(int fd, char *line, size_t len) { return false; while(!(newline = memchr(buffer, '\n', blen))) { - int result = recv(fd, buffer + blen, sizeof buffer - blen, 0); + int result = recv(fd, buffer + blen, sizeof(buffer) - blen, 0); if(result == -1 && sockerrno == EINTR) continue; else if(result <= 0) @@ -542,7 +542,7 @@ bool recvdata(int fd, char *data, size_t len) { len = blen; while(blen < len) { - int result = recv(fd, buffer + blen, sizeof buffer - blen, 0); + int result = recv(fd, buffer + blen, sizeof(buffer) - blen, 0); if(result == -1 && sockerrno == EINTR) continue; else if(result <= 0) @@ -564,11 +564,11 @@ bool sendline(int fd, char *format, ...) { va_list ap; va_start(ap, format); - blen = vsnprintf(buffer, sizeof buffer, format, ap); - buffer[sizeof buffer - 1] = 0; + blen = vsnprintf(buffer, sizeof(buffer), format, ap); + buffer[sizeof(buffer) - 1] = 0; va_end(ap); - if(blen < 1 || blen >= sizeof buffer) + if(blen < 1 || blen >= sizeof(buffer)) return false; buffer[blen] = '\n'; @@ -603,7 +603,7 @@ static void pcap(int fd, FILE *out, int snaplen) { 0xa1b2c3d4, 2, 4, 0, 0, - snaplen ?: sizeof data, + snaplen ?: sizeof(data), 1, }; @@ -616,15 +616,15 @@ static void pcap(int fd, FILE *out, int snaplen) { struct timeval tv; - fwrite(&header, sizeof header, 1, out); + fwrite(&header, sizeof(header), 1, out); fflush(out); char line[32]; - while(recvline(fd, line, sizeof line)) { + while(recvline(fd, line, sizeof(line))) { int code, req, len; 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 || len > sizeof(data)) break; if(!recvdata(fd, data, len)) break; @@ -632,7 +632,7 @@ static void pcap(int fd, FILE *out, int snaplen) { packet.tv_usec = tv.tv_usec; packet.len = len; packet.origlen = len; - fwrite(&packet, sizeof packet, 1, out); + fwrite(&packet, sizeof(packet), 1, out); fwrite(data, len, 1, out); fflush(out); } @@ -643,10 +643,10 @@ static void logcontrol(int fd, FILE *out, int level) { char data[1024]; char line[32]; - while(recvline(fd, line, sizeof line)) { + while(recvline(fd, line, sizeof(line))) { 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 || len > sizeof(data)) break; if(!recvdata(fd, data, len)) break; @@ -736,7 +736,7 @@ bool connect_tincd(bool verbose) { struct sockaddr_un sa; sa.sun_family = AF_UNIX; - strncpy(sa.sun_path, unixsocketname, sizeof sa.sun_path); + strncpy(sa.sun_path, unixsocketname, sizeof(sa.sun_path)); fd = socket(AF_UNIX, SOCK_STREAM, 0); if(fd < 0) { @@ -745,7 +745,7 @@ bool connect_tincd(bool verbose) { return false; } - if(connect(fd, (struct sockaddr *)&sa, sizeof sa) < 0) { + if(connect(fd, (struct sockaddr *)&sa, sizeof(sa)) < 0) { if(verbose) fprintf(stderr, "Cannot connect to UNIX socket %s: %s\n", unixsocketname, sockstrerror(sockerrno)); close(fd); @@ -797,13 +797,13 @@ bool connect_tincd(bool verbose) { #ifdef SO_NOSIGPIPE static const int one = 1; - setsockopt(fd, SOL_SOCKET, SO_NOSIGPIPE, (void *)&one, sizeof one); + setsockopt(fd, SOL_SOCKET, SO_NOSIGPIPE, (void *)&one, sizeof(one)); #endif char data[4096]; int version; - if(!recvline(fd, line, sizeof line) || sscanf(line, "%d %4095s %d", &code, data, &version) != 3 || code != 0) { + if(!recvline(fd, line, sizeof(line)) || sscanf(line, "%d %4095s %d", &code, data, &version) != 3 || code != 0) { if(verbose) fprintf(stderr, "Cannot read greeting from control socket: %s\n", sockstrerror(sockerrno)); close(fd); @@ -813,7 +813,7 @@ bool connect_tincd(bool verbose) { sendline(fd, "%d ^%s %d", ID, controlcookie, TINC_CTL_VERSION_CURRENT); - if(!recvline(fd, line, sizeof line) || sscanf(line, "%d %d %d", &code, &version, &pid) != 3 || code != 4 || version != TINC_CTL_VERSION_CURRENT) { + if(!recvline(fd, line, sizeof(line)) || sscanf(line, "%d %d %d", &code, &version, &pid) != 3 || code != 4 || version != TINC_CTL_VERSION_CURRENT) { if(verbose) fprintf(stderr, "Could not fully establish control socket connection\n"); close(fd); @@ -848,7 +848,7 @@ static int cmd_start(int argc, char *argv[]) { c = "tincd"; int nargc = 0; - char **nargv = xzalloc((optind + argc) * sizeof *nargv); + char **nargv = xzalloc((optind + argc) * sizeof(*nargv)); char *arg0 = c; #ifdef HAVE_MINGW @@ -893,7 +893,7 @@ static int cmd_start(int argc, char *argv[]) { if(!pid) { close(pfd[0]); char buf[100]; - snprintf(buf, sizeof buf, "%d", pfd[1]); + snprintf(buf, sizeof(buf), "%d", pfd[1]); setenv("TINC_UMBILICAL", buf, true); exit(execvp(c, nargv)); } else { @@ -913,7 +913,7 @@ static int cmd_start(int argc, char *argv[]) { char buf[1024]; ssize_t len; - while((len = read(pfd[0], buf, sizeof buf)) > 0) { + while((len = read(pfd[0], buf, sizeof(buf))) > 0) { failure = buf[len - 1]; if(!failure) len--; @@ -965,7 +965,7 @@ static int cmd_stop(int argc, char *argv[]) { sendline(fd, "%d %d", CONTROL, REQ_STOP); - while(recvline(fd, line, sizeof line)) { + while(recvline(fd, line, sizeof(line))) { // Wait for tincd to close the connection... } #else @@ -994,7 +994,7 @@ static int cmd_reload(int argc, char *argv[]) { return 1; sendline(fd, "%d %d", CONTROL, REQ_RELOAD); - if(!recvline(fd, line, sizeof line) || sscanf(line, "%d %d %d", &code, &req, &result) != 3 || code != CONTROL || req != REQ_RELOAD || result) { + if(!recvline(fd, line, sizeof(line)) || sscanf(line, "%d %d %d", &code, &req, &result) != 3 || code != CONTROL || req != REQ_RELOAD || result) { fprintf(stderr, "Could not reload configuration.\n"); return 1; } @@ -1005,7 +1005,7 @@ static int cmd_reload(int argc, char *argv[]) { static int dump_invitations(void) { char dname[PATH_MAX]; - snprintf(dname, sizeof dname, "%s" SLASH "invitations", confbase); + snprintf(dname, sizeof(dname), "%s" SLASH "invitations", confbase); DIR *dir = opendir(dname); if(!dir) { if(errno == ENOENT) { @@ -1026,7 +1026,7 @@ static int dump_invitations(void) { continue; char fname[PATH_MAX]; - snprintf(fname, sizeof fname, "%s" SLASH "%s", dname, ent->d_name); + snprintf(fname, sizeof(fname), "%s" SLASH "%s", dname, ent->d_name); FILE *f = fopen(fname, "r"); if(!f) { fprintf(stderr, "Cannot open %s: %s\n", fname, strerror(errno)); @@ -1034,7 +1034,7 @@ static int dump_invitations(void) { } buf[0] = 0; - if(!fgets(buf, sizeof buf, f)) { + if(!fgets(buf, sizeof(buf), f)) { fprintf(stderr, "Invalid invitation file %s", fname); fclose(f); continue; @@ -1116,7 +1116,7 @@ static int cmd_dump(int argc, char *argv[]) { else if(do_graph == 2) printf("digraph {\n"); - while(recvline(fd, line, sizeof line)) { + while(recvline(fd, line, sizeof(line))) { char node1[4096], node2[4096]; int n = sscanf(line, "%d %d %4095s %4095s", &code, &req, node1, node2); if(n == 2) { @@ -1156,7 +1156,7 @@ static int cmd_dump(int argc, char *argv[]) { return 1; } - memcpy(&status, &status_int, sizeof status); + memcpy(&status, &status_int, sizeof(status)); if(do_graph) { const char *color = "black"; @@ -1235,7 +1235,7 @@ static int cmd_purge(int argc, char *argv[]) { return 1; sendline(fd, "%d %d", CONTROL, REQ_PURGE); - if(!recvline(fd, line, sizeof line) || sscanf(line, "%d %d %d", &code, &req, &result) != 3 || code != CONTROL || req != REQ_PURGE || result) { + if(!recvline(fd, line, sizeof(line)) || sscanf(line, "%d %d %d", &code, &req, &result) != 3 || code != CONTROL || req != REQ_PURGE || result) { fprintf(stderr, "Could not purge old information.\n"); return 1; } @@ -1256,7 +1256,7 @@ static int cmd_debug(int argc, char *argv[]) { int origlevel; sendline(fd, "%d %d %d", CONTROL, REQ_SET_DEBUG, debuglevel); - if(!recvline(fd, line, sizeof line) || sscanf(line, "%d %d %d", &code, &req, &origlevel) != 3 || code != CONTROL || req != REQ_SET_DEBUG) { + if(!recvline(fd, line, sizeof(line)) || sscanf(line, "%d %d %d", &code, &req, &origlevel) != 3 || code != CONTROL || req != REQ_SET_DEBUG) { fprintf(stderr, "Could not set debug level.\n"); return 1; } @@ -1275,7 +1275,7 @@ static int cmd_retry(int argc, char *argv[]) { return 1; sendline(fd, "%d %d", CONTROL, REQ_RETRY); - if(!recvline(fd, line, sizeof line) || sscanf(line, "%d %d %d", &code, &req, &result) != 3 || code != CONTROL || req != REQ_RETRY || result) { + if(!recvline(fd, line, sizeof(line)) || sscanf(line, "%d %d %d", &code, &req, &result) != 3 || code != CONTROL || req != REQ_RETRY || result) { fprintf(stderr, "Could not retry outgoing connections.\n"); return 1; } @@ -1298,7 +1298,7 @@ static int cmd_connect(int argc, char *argv[]) { return 1; sendline(fd, "%d %d %s", CONTROL, REQ_CONNECT, argv[1]); - if(!recvline(fd, line, sizeof line) || sscanf(line, "%d %d %d", &code, &req, &result) != 3 || code != CONTROL || req != REQ_CONNECT || result) { + if(!recvline(fd, line, sizeof(line)) || sscanf(line, "%d %d %d", &code, &req, &result) != 3 || code != CONTROL || req != REQ_CONNECT || result) { fprintf(stderr, "Could not connect to %s.\n", argv[1]); return 1; } @@ -1321,7 +1321,7 @@ static int cmd_disconnect(int argc, char *argv[]) { return 1; sendline(fd, "%d %d %s", CONTROL, REQ_DISCONNECT, argv[1]); - if(!recvline(fd, line, sizeof line) || sscanf(line, "%d %d %d", &code, &req, &result) != 3 || code != CONTROL || req != REQ_DISCONNECT || result) { + if(!recvline(fd, line, sizeof(line)) || sscanf(line, "%d %d %d", &code, &req, &result) != 3 || code != CONTROL || req != REQ_DISCONNECT || result) { fprintf(stderr, "Could not disconnect %s.\n", argv[1]); return 1; } @@ -1421,7 +1421,7 @@ char *get_my_name(bool verbose) { char buf[4096]; char *value; - while(fgets(buf, sizeof buf, f)) { + while(fgets(buf, sizeof(buf), f)) { int len = strcspn(buf, "\t ="); value = buf + len; value += strspn(value, "\t "); @@ -1449,7 +1449,7 @@ char *get_my_name(bool verbose) { ecdsa_t *get_pubkey(FILE *f) { char buf[4096]; char *value; - while(fgets(buf, sizeof buf, f)) { + while(fgets(buf, sizeof(buf), f)) { int len = strcspn(buf, "\t ="); value = buf + len; value += strspn(value, "\t "); @@ -1573,10 +1573,10 @@ static int cmd_config(int argc, char *argv[]) { } // Concatenate the rest of the command line - strncpy(line, argv[1], sizeof line - 1); + strncpy(line, argv[1], sizeof(line) - 1); for(int i = 2; i < argc; i++) { - strncat(line, " ", sizeof line - 1 - strlen(line)); - strncat(line, argv[i], sizeof line - 1 - strlen(line)); + strncat(line, " ", sizeof(line) - 1 - strlen(line)); + strncat(line, argv[i], sizeof(line) - 1 - strlen(line)); } // Liberal parsing into node name, variable name and value. @@ -1685,9 +1685,9 @@ static int cmd_config(int argc, char *argv[]) { // Open the right configuration file. char filename[PATH_MAX]; if(node) - snprintf(filename, sizeof filename, "%s" SLASH "%s", hosts_dir, node); + snprintf(filename, sizeof(filename), "%s" SLASH "%s", hosts_dir, node); else - snprintf(filename, sizeof filename, "%s", tinc_conf); + snprintf(filename, sizeof(filename), "%s", tinc_conf); FILE *f = fopen(filename, "r"); if(!f) { @@ -1699,7 +1699,7 @@ static int cmd_config(int argc, char *argv[]) { FILE *tf = NULL; if(action >= -1) { - snprintf(tmpfile, sizeof tmpfile, "%s.config.tmp", filename); + snprintf(tmpfile, sizeof(tmpfile), "%s.config.tmp", filename); tf = fopen(tmpfile, "w"); if(!tf) { fprintf(stderr, "Could not open temporary file %s: %s\n", tmpfile, strerror(errno)); @@ -1715,9 +1715,9 @@ static int cmd_config(int argc, char *argv[]) { bool removed = false; found = false; - while(fgets(buf1, sizeof buf1, f)) { - buf1[sizeof buf1 - 1] = 0; - strncpy(buf2, buf1, sizeof buf2); + while(fgets(buf1, sizeof(buf1), f)) { + buf1[sizeof(buf1) - 1] = 0; + strncpy(buf2, buf1, sizeof(buf2)); // Parse line in a simple way char *bvalue; @@ -1858,7 +1858,7 @@ static bool try_bind(int port) { bool success = true; char portstr[16]; - snprintf(portstr, sizeof portstr, "%d", port); + snprintf(portstr, sizeof(portstr), "%d", port); if(getaddrinfo(NULL, portstr, &hint, &ai) || !ai) return false; @@ -1892,7 +1892,7 @@ int check_port(char *name) { int port = 0x1000 + (rand() & 0x7fff); if(try_bind(port)) { char filename[PATH_MAX]; - snprintf(filename, sizeof filename, "%s" SLASH "hosts" SLASH "%s", confbase, name); + snprintf(filename, sizeof(filename), "%s" SLASH "hosts" SLASH "%s", confbase, name); FILE *f = fopen(filename, "a"); if(!f) { fprintf(stderr, "Could not open %s: %s\n", filename, strerror(errno)); @@ -1924,7 +1924,7 @@ static int cmd_init(int argc, char *argv[]) { if(tty) { char buf[1024]; fprintf(stderr, "Enter the Name you want your tinc node to have: "); - if(!fgets(buf, sizeof buf, stdin)) { + if(!fgets(buf, sizeof(buf), stdin)) { fprintf(stderr, "Error while reading stdin: %s\n", strerror(errno)); return 1; } @@ -1987,7 +1987,7 @@ static int cmd_init(int argc, char *argv[]) { #ifndef HAVE_MINGW char filename[PATH_MAX]; - snprintf(filename, sizeof filename, "%s" SLASH "tinc-up", confbase); + snprintf(filename, sizeof(filename), "%s" SLASH "tinc-up", confbase); if(access(filename, F_OK)) { FILE *f = fopenmask(filename, "w", 0777); if(!f) { @@ -2102,7 +2102,7 @@ static int cmd_edit(int argc, char *argv[]) { if(strncmp(argv[1], "hosts" SLASH, 6)) { for(int i = 0; conffiles[i]; i++) { if(!strcmp(argv[1], conffiles[i])) { - snprintf(filename, sizeof filename, "%s" SLASH "%s", confbase, argv[1]); + snprintf(filename, sizeof(filename), "%s" SLASH "%s", confbase, argv[1]); break; } } @@ -2111,7 +2111,7 @@ static int cmd_edit(int argc, char *argv[]) { } if(!*filename) { - snprintf(filename, sizeof filename, "%s" SLASH "%s", hosts_dir, argv[1]); + snprintf(filename, sizeof(filename), "%s" SLASH "%s", hosts_dir, argv[1]); char *dash = strchr(argv[1], '-'); if(dash) { *dash++ = 0; @@ -2142,7 +2142,7 @@ static int cmd_edit(int argc, char *argv[]) { static int export(const char *name, FILE *out) { char filename[PATH_MAX]; - snprintf(filename, sizeof filename, "%s" SLASH "%s", hosts_dir, name); + snprintf(filename, sizeof(filename), "%s" SLASH "%s", hosts_dir, name); FILE *in = fopen(filename, "r"); if(!in) { fprintf(stderr, "Could not open configuration file %s: %s\n", filename, strerror(errno)); @@ -2151,7 +2151,7 @@ static int export(const char *name, FILE *out) { fprintf(out, "Name = %s\n", name); char buf[4096]; - while(fgets(buf, sizeof buf, in)) { + while(fgets(buf, sizeof(buf), in)) { if(strcspn(buf, "\t =") != 4 || strncasecmp(buf, "Name", 4)) fputs(buf, out); } @@ -2233,7 +2233,7 @@ static int cmd_import(int argc, char *argv[]) { int count = 0; bool firstline = true; - while(fgets(buf, sizeof buf, in)) { + while(fgets(buf, sizeof(buf), in)) { if(sscanf(buf, "Name = %4095s", name) == 1) { firstline = false; @@ -2245,7 +2245,7 @@ static int cmd_import(int argc, char *argv[]) { if(out) fclose(out); - snprintf(filename, sizeof filename, "%s" SLASH "%s", hosts_dir, name); + snprintf(filename, sizeof(filename), "%s" SLASH "%s", hosts_dir, name); if(!force && !access(filename, F_OK)) { fprintf(stderr, "Host configuration file %s already exists, skipping.\n", filename); @@ -2355,7 +2355,7 @@ static int cmd_network(int argc, char *argv[]) { } char fname[PATH_MAX]; - snprintf(fname, sizeof fname, "%s/%s/tinc.conf", confdir, ent->d_name); + snprintf(fname, sizeof(fname), "%s/%s/tinc.conf", confdir, ent->d_name); if(!access(fname, R_OK)) printf("%s\n", ent->d_name); } @@ -2409,7 +2409,7 @@ static int cmd_sign(int argc, char *argv[]) { } char fname[PATH_MAX]; - snprintf(fname, sizeof fname, "%s" SLASH "ed25519_key.priv", confbase); + snprintf(fname, sizeof(fname), "%s" SLASH "ed25519_key.priv", confbase); FILE *fp = fopen(fname, "r"); if(!fp) { fprintf(stderr, "Could not open %s: %s\n", fname, strerror(errno)); @@ -2565,7 +2565,7 @@ static int cmd_verify(int argc, char *argv[]) { newline = data + skip; char fname[PATH_MAX]; - snprintf(fname, sizeof fname, "%s" SLASH "hosts" SLASH "%s", confbase, node); + snprintf(fname, sizeof(fname), "%s" SLASH "hosts" SLASH "%s", confbase, node); FILE *fp = fopen(fname, "r"); if(!fp) { fprintf(stderr, "Could not open %s: %s\n", fname, strerror(errno)); @@ -2724,7 +2724,7 @@ static char *complete_info(const char *text, int state) { sendline(fd, "%d %d", CONTROL, REQ_DUMP_SUBNETS); } - while(recvline(fd, line, sizeof line)) { + while(recvline(fd, line, sizeof(line))) { char item[4096]; int n = sscanf(line, "%d %d %4095s", &code, &req, item); if(n == 2) { @@ -2779,7 +2779,7 @@ static int cmd_shell(int argc, char *argv[]) { char buf[4096]; char *line = NULL; int maxargs = argc + 16; - char **nargv = xmalloc(maxargs * sizeof *nargv); + char **nargv = xmalloc(maxargs * sizeof(*nargv)); for(int i = 0; i < argc; i++) nargv[i] = argv[i]; @@ -2802,13 +2802,13 @@ static int cmd_shell(int argc, char *argv[]) { if(line) copy = xstrdup(line); } else { - line = fgets(buf, sizeof buf, stdin); + line = fgets(buf, sizeof(buf), stdin); } #else if(tty) fputs(prompt, stdout); - line = fgets(buf, sizeof buf, stdin); + line = fgets(buf, sizeof(buf), stdin); #endif if(!line) @@ -2828,7 +2828,7 @@ static int cmd_shell(int argc, char *argv[]) { while(p && *p) { if(nargc >= maxargs) { maxargs *= 2; - nargv = xrealloc(nargv, maxargs * sizeof *nargv); + nargv = xrealloc(nargv, maxargs * sizeof(*nargv)); } nargv[nargc++] = p; diff --git a/src/top.c b/src/top.c index 8227d6c7..8d9ffb09 100644 --- a/src/top.c +++ b/src/top.c @@ -89,7 +89,7 @@ static bool update(int fd) { for list_each(nodestats_t, ns, &node_list) ns->known = false; - while(recvline(fd, line, sizeof line)) { + while(recvline(fd, line, sizeof(line))) { int n = sscanf(line, "%d %d %4095s %"PRIu64" %"PRIu64" %"PRIu64" %"PRIu64, &code, &req, name, &in_packets, &in_bytes, &out_packets, &out_bytes); if(n == 2) @@ -108,7 +108,7 @@ static bool update(int fd) { found = ns; break; } else { - found = xzalloc(sizeof *found); + found = xzalloc(sizeof(*found)); found->name = xstrdup(name); list_insert_before(&node_list, node, found); changed = true; @@ -117,7 +117,7 @@ static bool update(int fd) { } if(!found) { - found = xzalloc(sizeof *found); + found = xzalloc(sizeof(*found)); found->name = xstrdup(name); list_insert_tail(&node_list, found); changed = true; @@ -220,7 +220,7 @@ static void redraw(void) { static int n = 0; if(changed) { n = 0; - sorted = xrealloc(sorted, node_list.count * sizeof *sorted); + sorted = xrealloc(sorted, node_list.count * sizeof(*sorted)); for list_each(nodestats_t, ns, &node_list) sorted[n++] = ns; changed = false; @@ -230,7 +230,7 @@ static void redraw(void) { sorted[i]->i = i; if(sorted) - qsort(sorted, n, sizeof *sorted, sortfunc); + qsort(sorted, n, sizeof(*sorted), sortfunc); for(int i = 0, row = 3; i < n; i++, row++) { nodestats_t *node = sorted[i]; diff --git a/src/uml_device.c b/src/uml_device.c index 68f4cd25..829e1411 100644 --- a/src/uml_device.c +++ b/src/uml_device.c @@ -76,7 +76,7 @@ static bool setup_device(void) { fcntl(write_fd, F_SETFD, FD_CLOEXEC); #endif - setsockopt(write_fd, SOL_SOCKET, SO_REUSEADDR, &one, sizeof one); + setsockopt(write_fd, SOL_SOCKET, SO_REUSEADDR, &one, sizeof(one)); if(fcntl(write_fd, F_SETFL, O_NONBLOCK) < 0) { logger(DEBUG_ALWAYS, LOG_ERR, "System call `%s' failed: %s", "fcntl", strerror(errno)); @@ -94,7 +94,7 @@ static bool setup_device(void) { fcntl(data_fd, F_SETFD, FD_CLOEXEC); #endif - setsockopt(data_fd, SOL_SOCKET, SO_REUSEADDR, &one, sizeof one); + setsockopt(data_fd, SOL_SOCKET, SO_REUSEADDR, &one, sizeof(one)); if(fcntl(data_fd, F_SETFL, O_NONBLOCK) < 0) { logger(DEBUG_ALWAYS, LOG_ERR, "System call `%s' failed: %s", "fcntl", strerror(errno)); @@ -107,9 +107,9 @@ static bool setup_device(void) { gettimeofday(&tv, NULL); name.usecs = tv.tv_usec; data_sun.sun_family = AF_UNIX; - memcpy(&data_sun.sun_path, &name, sizeof name); + memcpy(&data_sun.sun_path, &name, sizeof(name)); - if(bind(data_fd, (struct sockaddr *)&data_sun, sizeof data_sun) < 0) { + if(bind(data_fd, (struct sockaddr *)&data_sun, sizeof(data_sun)) < 0) { logger(DEBUG_ALWAYS, LOG_ERR, "Could not bind data %s: %s", device_info, strerror(errno)); event_exit(); return false; @@ -125,7 +125,7 @@ static bool setup_device(void) { fcntl(device_fd, F_SETFD, FD_CLOEXEC); #endif - setsockopt(listen_fd, SOL_SOCKET, SO_REUSEADDR, &one, sizeof one); + setsockopt(listen_fd, SOL_SOCKET, SO_REUSEADDR, &one, sizeof(one)); if(fcntl(listen_fd, F_SETFL, O_NONBLOCK) < 0) { logger(DEBUG_ALWAYS, LOG_ERR, "System call `%s' failed: %s", "fcntl", strerror(errno)); @@ -133,8 +133,8 @@ static bool setup_device(void) { } listen_sun.sun_family = AF_UNIX; - strncpy(listen_sun.sun_path, device, sizeof listen_sun.sun_path); - if(bind(listen_fd, (struct sockaddr *)&listen_sun, sizeof listen_sun) < 0) { + strncpy(listen_sun.sun_path, device, sizeof(listen_sun.sun_path)); + if(bind(listen_fd, (struct sockaddr *)&listen_sun, sizeof(listen_sun)) < 0) { logger(DEBUG_ALWAYS, LOG_ERR, "Could not bind %s to %s: %s", device_info, device, strerror(errno)); return false; } @@ -187,7 +187,7 @@ static bool read_packet(vpn_packet_t *packet) { switch(state) { case 0: { struct sockaddr sa; - socklen_t salen = sizeof sa; + socklen_t salen = sizeof(sa); request_fd = accept(listen_fd, &sa, &salen); if(request_fd < 0) { @@ -214,7 +214,7 @@ static bool read_packet(vpn_packet_t *packet) { } case 1: { - if((inlen = read(request_fd, &request, sizeof request)) != sizeof request) { + if((inlen = read(request_fd, &request, sizeof(request))) != sizeof request) { logger(DEBUG_ALWAYS, LOG_ERR, "Error while reading request from %s %s: %s", device_info, device, strerror(errno)); event_exit(); @@ -228,13 +228,13 @@ static bool read_packet(vpn_packet_t *packet) { return false; } - if(connect(write_fd, (struct sockkadr *)&request.sock, sizeof request.sock) < 0) { + if(connect(write_fd, (struct sockkadr *)&request.sock, sizeof(request.sock)) < 0) { logger(DEBUG_ALWAYS, LOG_ERR, "Could not bind write %s: %s", device_info, strerror(errno)); event_exit(); return false; } - write(request_fd, &data_sun, sizeof data_sun); + write(request_fd, &data_sun, sizeof(data_sun)); device_fd = data_fd; logger(DEBUG_ALWAYS, LOG_INFO, "Connection with UML established"); diff --git a/src/upnp.c b/src/upnp.c index 3bfc770f..e321dcf0 100644 --- a/src/upnp.c +++ b/src/upnp.c @@ -75,7 +75,7 @@ static void upnp_add_mapping(struct UPNPUrls *urls, struct IGDdatas *data, const // Note that we can't simply use listen_socket[].sa because this won't have the port // if we're running with Port=0 (dynamically assigned port). sockaddr_t sa; - socklen_t salen = sizeof sa; + socklen_t salen = sizeof(sa); if (getsockname(socket, &sa.sa, &salen)) { logger(DEBUG_PROTOCOL, LOG_ERR, "[upnp] Unable to get socket address: [%d] %s", sockerrno, sockstrerror(sockerrno)); return; @@ -89,7 +89,7 @@ static void upnp_add_mapping(struct UPNPUrls *urls, struct IGDdatas *data, const // Use a lease twice as long as the refresh period so that the mapping won't expire before we refresh. char lease_duration[16]; - snprintf(lease_duration, sizeof lease_duration, "%d", upnp_refresh_period * 2); + snprintf(lease_duration, sizeof(lease_duration), "%d", upnp_refresh_period * 2); int error = UPNP_AddPortMapping(urls->controlURL, data->first.servicetype, port, port, myaddr, identname, proto, NULL, lease_duration); if (error == 0) { @@ -115,7 +115,7 @@ static void upnp_refresh() { struct UPNPUrls urls; struct IGDdatas data; char myaddr[64]; - int result = UPNP_GetValidIGD(devices, &urls, &data, myaddr, sizeof myaddr); + int result = UPNP_GetValidIGD(devices, &urls, &data, myaddr, sizeof(myaddr)); if (result <= 0) { logger(DEBUG_PROTOCOL, LOG_WARNING, "[upnp] No IGD found"); freeUPNPDevlist(devices); diff --git a/src/utils.c b/src/utils.c index fadfd05f..940bc6e7 100644 --- a/src/utils.c +++ b/src/utils.c @@ -158,7 +158,7 @@ int b64encode_urlsafe(const void *src, char *dst, int length) { const char *winerror(int err) { static char buf[1024], *ptr; - ptr = buf + snprintf(buf, sizeof buf, "(%d) ", err); + ptr = buf + snprintf(buf, sizeof(buf), "(%d) ", err); if (!FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, NULL, err, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), ptr, sizeof(buf) - (ptr - buf), NULL)) { @@ -174,8 +174,8 @@ const char *winerror(int err) { unsigned int bitfield_to_int(const void *bitfield, size_t size) { unsigned int value = 0; - if(size > sizeof value) - size = sizeof value; + if(size > sizeof(value)) + size = sizeof(value); memcpy(&value, bitfield, size); return value; } @@ -223,7 +223,7 @@ char *replace_name(const char *name) { logger(DEBUG_ALWAYS, LOG_ERR, "Invalid Name: environment variable %s does not exist\n", name + 1); return NULL; } - if (gethostname(hostname, sizeof hostname) || !*hostname) { + if (gethostname(hostname, sizeof(hostname)) || !*hostname) { logger(DEBUG_ALWAYS, LOG_ERR, "Could not get hostname: %s\n", sockstrerror(sockerrno)); return NULL; } diff --git a/src/xalloc.h b/src/xalloc.h index 34dac3cc..1bde0415 100644 --- a/src/xalloc.h +++ b/src/xalloc.h @@ -55,7 +55,7 @@ static inline char *xstrdup(const char *s) { static inline int xvasprintf(char **strp, const char *fmt, va_list ap) { #ifdef HAVE_MINGW char buf[1024]; - int result = vsnprintf(buf, sizeof buf, fmt, ap); + int result = vsnprintf(buf, sizeof(buf), fmt, ap); if(result < 0) abort(); *strp = xstrdup(buf); diff --git a/test/pong.c b/test/pong.c index a4f2be73..24a215c7 100644 --- a/test/pong.c +++ b/test/pong.c @@ -25,10 +25,10 @@ uint8_t mymac[6] = {6, 5, 5, 6, 5, 5}; static ssize_t do_arp(uint8_t *buf, ssize_t len, struct sockaddr_in *in) { struct ether_arp arp; - memcpy(&arp, buf + 14, sizeof arp); + memcpy(&arp, buf + 14, sizeof(arp)); // Is it a valid ARP request? - if(ntohs(arp.arp_hrd) != ARPHRD_ETHER || ntohs(arp.arp_pro) != ETH_P_IP || arp.arp_hln != ETH_ALEN || arp.arp_pln != sizeof in->sin_addr.s_addr || ntohs(arp.arp_op) != ARPOP_REQUEST) + if(ntohs(arp.arp_hrd) != ARPHRD_ETHER || ntohs(arp.arp_pro) != ETH_P_IP || arp.arp_hln != ETH_ALEN || arp.arp_pln != sizeof(in->sin_addr.s_addr) || ntohs(arp.arp_op) != ARPOP_REQUEST) return 0; // Does it match our address? @@ -40,12 +40,12 @@ static ssize_t do_arp(uint8_t *buf, ssize_t len, struct sockaddr_in *in) { memcpy(buf + 6, mymac, 6); arp.arp_op = htons(ARPOP_REPLY); - memcpy(arp.arp_tpa, arp.arp_spa, sizeof arp.arp_tpa); - memcpy(arp.arp_tha, arp.arp_sha, sizeof arp.arp_tha); - memcpy(arp.arp_spa, &in->sin_addr.s_addr, sizeof in->sin_addr.s_addr); + memcpy(arp.arp_tpa, arp.arp_spa, sizeof(arp.arp_tpa)); + memcpy(arp.arp_tha, arp.arp_sha, sizeof(arp.arp_tha)); + memcpy(arp.arp_spa, &in->sin_addr.s_addr, sizeof(in->sin_addr.s_addr)); memcpy(arp.arp_sha, mymac, 6); - memcpy(buf + 14, &arp, sizeof arp); + memcpy(buf + 14, &arp, sizeof(arp)); return len; } @@ -58,7 +58,7 @@ static ssize_t do_ipv4(uint8_t *buf, ssize_t len, struct sockaddr_in *in) { if(memcmp(buf, mymac, 6)) return 0; - memcpy(&ip, buf + 14, sizeof ip); + memcpy(&ip, buf + 14, sizeof(ip)); if(memcmp(&ip.ip_dst, &in->sin_addr.s_addr, 4)) return 0; @@ -66,7 +66,7 @@ static ssize_t do_ipv4(uint8_t *buf, ssize_t len, struct sockaddr_in *in) { if(ip.ip_p != IPPROTO_ICMP) return 0; - memcpy(&icmp, buf + 14 + sizeof ip, sizeof icmp); + memcpy(&icmp, buf + 14 + sizeof(ip), sizeof icmp); if(icmp.icmp_type != ICMP_ECHO) return 0; @@ -79,8 +79,8 @@ static ssize_t do_ipv4(uint8_t *buf, ssize_t len, struct sockaddr_in *in) { icmp.icmp_type = ICMP_ECHOREPLY; - memcpy(buf + 14, &ip, sizeof ip); - memcpy(buf + 14 + sizeof ip, &icmp, sizeof icmp); + memcpy(buf + 14, &ip, sizeof(ip)); + memcpy(buf + 14 + sizeof(ip), &icmp, sizeof icmp); return len; } @@ -113,7 +113,7 @@ int main(int argc, char *argv[]) { } static const int one = 1; - setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, (void *)&one, sizeof one); + setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, (void *)&one, sizeof(one)); if(bind(fd, ai->ai_addr, ai->ai_addrlen)) { fprintf(stderr, "Could not bind socket: %s\n", strerror(errno)); @@ -124,15 +124,15 @@ int main(int argc, char *argv[]) { case AF_INET: { struct ip_mreq mreq; struct sockaddr_in in; - memcpy(&in, ai->ai_addr, sizeof in); + memcpy(&in, ai->ai_addr, sizeof(in)); mreq.imr_multiaddr.s_addr = in.sin_addr.s_addr; mreq.imr_interface.s_addr = htonl(INADDR_ANY); - if(setsockopt(fd, IPPROTO_IP, IP_ADD_MEMBERSHIP, (void *)&mreq, sizeof mreq)) { + if(setsockopt(fd, IPPROTO_IP, IP_ADD_MEMBERSHIP, (void *)&mreq, sizeof(mreq))) { fprintf(stderr, "Cannot join multicast group: %s\n", strerror(errno)); return 1; } #ifdef IP_MULTICAST_LOOP - setsockopt(fd, IPPROTO_IP, IP_MULTICAST_LOOP, (const void *)&one, sizeof one); + setsockopt(fd, IPPROTO_IP, IP_MULTICAST_LOOP, (const void *)&one, sizeof(one)); #endif } break; @@ -140,15 +140,15 @@ int main(int argc, char *argv[]) { case AF_INET6: { struct ipv6_mreq mreq; struct sockaddr_in6 in6; - memcpy(&in6, ai->ai_addr, sizeof in6); - memcpy(&mreq.ipv6mr_multiaddr, &in6.sin6_addr, sizeof mreq.ipv6mr_multiaddr); + memcpy(&in6, ai->ai_addr, sizeof(in6)); + memcpy(&mreq.ipv6mr_multiaddr, &in6.sin6_addr, sizeof(mreq.ipv6mr_multiaddr)); mreq.ipv6mr_interface = in6.sin6_scope_id; - if(setsockopt(fd, IPPROTO_IPV6, IPV6_JOIN_GROUP, (void *)&mreq, sizeof mreq)) { + if(setsockopt(fd, IPPROTO_IPV6, IPV6_JOIN_GROUP, (void *)&mreq, sizeof(mreq))) { fprintf(stderr, "Cannot join multicast group: %s\n", strerror(errno)); return 1; } #ifdef IPV6_MULTICAST_LOOP - setsockopt(fd, IPPROTO_IPV6, IPV6_MULTICAST_LOOP, (const void *)&one, sizeof one); + setsockopt(fd, IPPROTO_IPV6, IPV6_MULTICAST_LOOP, (const void *)&one, sizeof(one)); #endif } break; #endif @@ -169,7 +169,7 @@ int main(int argc, char *argv[]) { uint8_t buf[10000]; struct sockaddr src; socklen_t srclen; - ssize_t len = recvfrom(fd, buf, sizeof buf, 0, &src, &srclen); + ssize_t len = recvfrom(fd, buf, sizeof(buf), 0, &src, &srclen); if(len <= 0) break;