X-Git-Url: https://www.tinc-vpn.org/git/browse?p=tinc;a=blobdiff_plain;f=src%2Finvitation.c;h=500f2434b77e150a0d2f566e2fa89e6693d13380;hp=c3072cf2622dd7680d1ff828fcffd84035584583;hb=1c475ecb575367a6b3f9328b0f643ad636155341;hpb=953f5b4231bbbb8269bb0c55b96a1c8c4bb34a59 diff --git a/src/invitation.c b/src/invitation.c index c3072cf2..500f2434 100644 --- a/src/invitation.c +++ b/src/invitation.c @@ -356,7 +356,7 @@ int cmd_invite(int argc, char *argv[]) { char invname[PATH_MAX]; struct stat st; - if(snprintf(invname, sizeof(invname), "%s" SLASH "%s", filename, ent->d_name) >= sizeof(invname)) { + if((size_t)snprintf(invname, sizeof(invname), "%s" SLASH "%s", filename, ent->d_name) >= sizeof(invname)) { fprintf(stderr, "Filename too long: %s" SLASH "%s\n", filename, ent->d_name); continue; } @@ -555,7 +555,7 @@ static char *get_line(const char **data) { static char line[1024]; const char *end = strchr(*data, '\n'); - size_t len = end ? end - *data : strlen(*data); + size_t len = end ? (size_t)(end - *data) : strlen(*data); if(len >= sizeof(line)) { fprintf(stderr, "Maximum line length exceeded!\n"); @@ -635,7 +635,7 @@ static char *grep(const char *data, const char *var) { return xstrdup(p); } - if(e - p >= sizeof(value)) { + if((size_t)(e - p) >= sizeof(value)) { fprintf(stderr, "Maximum line length exceeded!\n"); return NULL; } @@ -646,13 +646,18 @@ static char *grep(const char *data, const char *var) { } static bool finalize_join(void) { - const char *name = get_value(data, "Name"); + const char *temp_name = get_value(data, "Name"); - if(!name) { + if(!temp_name) { fprintf(stderr, "No Name found in invitation!\n"); return false; } + size_t len = strlen(temp_name); + char name[len + 1]; + memcpy(name, temp_name, len); + name[len] = 0; + if(!check_id(name)) { fprintf(stderr, "Invalid Name found in invitation!\n"); return false; @@ -962,7 +967,7 @@ ask_netname: char newbase[PATH_MAX]; - if(snprintf(newbase, sizeof(newbase), CONFDIR SLASH "tinc" SLASH "%s", line) >= sizeof(newbase)) { + if((size_t)snprintf(newbase, sizeof(newbase), CONFDIR SLASH "tinc" SLASH "%s", line) >= sizeof(newbase)) { fprintf(stderr, "Filename too long: " CONFDIR SLASH "tinc" SLASH "%s\n", line); goto ask_netname; } @@ -1007,7 +1012,13 @@ ask_netname: if(response == 'e') { char *command; #ifndef HAVE_MINGW - xasprintf(&command, "\"%s\" \"%s\"", getenv("VISUAL") ? : getenv("EDITOR") ? : "vi", filename); + const char *editor = getenv("VISUAL"); + if (!editor) + editor = getenv("EDITOR"); + if (!editor) + editor = "vi"; + + xasprintf(&command, "\"%s\" \"%s\"", editor, filename); #else xasprintf(&command, "edit \"%s\"", filename); #endif @@ -1044,7 +1055,11 @@ ask_netname: } -static bool invitation_send(void *handle, uint8_t type, const void *data, size_t len) { +static bool invitation_send(void *handle, uint8_t type, const void *vdata, size_t len) { + (void)handle; + (void)type; + const char *data = vdata; + while(len) { int result = send(sock, data, len, 0); @@ -1062,6 +1077,8 @@ static bool invitation_send(void *handle, uint8_t type, const void *data, size_t } static bool invitation_receive(void *handle, uint8_t type, const void *msg, uint16_t len) { + (void)handle; + switch(type) { case SPTPS_HANDSHAKE: return sptps_send_record(&sptps, 0, cookie, sizeof(cookie)); @@ -1240,7 +1257,7 @@ next: // Tell him we have an invitation, and give him our throw-away key. int len = snprintf(line, sizeof(line), "0 ?%s %d.%d\n", b64key, PROT_MAJOR, PROT_MINOR); - if(len <= 0 || len >= sizeof(line)) { + if(len <= 0 || (size_t)len >= sizeof(line)) { abort(); }