X-Git-Url: https://tinc-vpn.org/git/browse?a=blobdiff_plain;f=src%2Finvitation.c;h=d615976d84bb43c0a6d1706a6a9dc64db13290da;hb=d72a450975bed625e058eb857410f0d78caee2d1;hp=29769686e96f1cf775929a9cc0ec7e85e690a024;hpb=2bc475274bd467532a1de0cf708072292d215474;p=tinc diff --git a/src/invitation.c b/src/invitation.c index 29769686..d615976d 100644 --- a/src/invitation.c +++ b/src/invitation.c @@ -111,6 +111,9 @@ char *get_my_hostname() { scan_for_hostname(tinc_conf, &hostname, &port); } + free(name); + name = NULL; + if(hostname) { goto done; } @@ -407,6 +410,7 @@ int cmd_invite(int argc, char *argv[]) { if(!f) { fprintf(stderr, "Could not write %s: %s\n", filename, strerror(errno)); + free(key); return 1; } @@ -415,6 +419,7 @@ int cmd_invite(int argc, char *argv[]) { if(!ecdsa_write_pem_private_key(key, f)) { fprintf(stderr, "Could not write ECDSA private key\n"); fclose(f); + free(key); return 1; } @@ -444,6 +449,8 @@ int cmd_invite(int argc, char *argv[]) { sha512(fingerprint, strlen(fingerprint), hash); b64encode_urlsafe(hash, hash, 18); + free(key); + // Create a random cookie for this invitation. char cookie[25]; randomize(cookie, 18); @@ -456,6 +463,8 @@ int cmd_invite(int argc, char *argv[]) { sha512(buf, sizeof(buf), cookiehash); b64encode_urlsafe(cookiehash, cookiehash, 18); + free(fingerprint); + b64encode_urlsafe(cookie, cookie, 18); // Create a file containing the details of the invitation. @@ -1054,7 +1063,13 @@ ask_netname: } } } else { - fprintf(stderr, "A tinc-up script was generated, but has been left disabled.\n"); + if(force) { + rename(filename, filename2); + chmod(filename2, 0755); + fprintf(stderr, "tinc-up enabled.\n"); + } else { + fprintf(stderr, "A tinc-up script was generated, but has been left disabled.\n"); + } } } else { // A placeholder was generated. @@ -1076,7 +1091,7 @@ static bool invitation_send(void *handle, uint8_t type, const void *vdata, size_ while(len) { int result = send(sock, data, len, 0); - if(result == -1 && errno == EINTR) { + if(result == -1 && sockwouldblock(sockerrno)) { continue; } else if(result <= 0) { return false; @@ -1231,6 +1246,7 @@ int cmd_join(int argc, char *argv[]) { struct addrinfo *ai = str2addrinfo(address, port, SOCK_STREAM); if(!ai) { + free(b64key); return 1; } @@ -1244,6 +1260,7 @@ next: if(!aip) { freeaddrinfo(ai); + free(b64key); return 1; } } @@ -1290,6 +1307,11 @@ next: } freeaddrinfo(ai); + ai = NULL; + aip = NULL; + + free(b64key); + b64key = NULL; // Check if the hash of the key he gave us matches the hash in the URL. char *fingerprint = line + 2; @@ -1324,11 +1346,21 @@ next: while((len = recv(sock, line, sizeof(line), 0))) { if(len < 0) { - if(errno == EINTR) { + if(sockwouldblock(sockerrno)) { continue; } - fprintf(stderr, "Error reading data from %s port %s: %s\n", address, port, strerror(errno)); +#if HAVE_MINGW + + // If socket has been shut down, recv() on Windows returns -1 and sets sockerrno + // to WSAESHUTDOWN, while on UNIX-like operating systems recv() returns 0, so we + // have to do an explicit check here. + if(sockshutdown(sockerrno)) { + break; + } + +#endif + fprintf(stderr, "Error reading data from %s port %s: %s\n", address, port, sockstrerror(sockerrno)); return 1; }