X-Git-Url: http://git.meshlink.io/?p=meshlink;a=blobdiff_plain;f=src%2Fprotocol_auth.c;h=4ba3ebe4282dc1742942b2944a31309a233559da;hp=b11acaef7c5e4238dcba37af577bb8077da2fef3;hb=34a52e6e69be085ee99755c2890268d2ce11f9b4;hpb=fe4cf1f57aa26458d1c2a9c44a06f9e49fe8d615 diff --git a/src/protocol_auth.c b/src/protocol_auth.c index b11acaef..4ba3ebe4 100644 --- a/src/protocol_auth.c +++ b/src/protocol_auth.c @@ -239,6 +239,24 @@ static bool receive_invitation_sptps(void *handle, uint8_t type, const void *dat if(!f) { logger(mesh, MESHLINK_ERROR, "Error trying to open invitation %s\n", cookie); + unlink(usedname); + return false; + } + + // Check the timestamp + struct stat st; + + if(fstat(fileno(f), &st)) { + logger(mesh, MESHLINK_ERROR, "Could not stat invitation file %s\n", usedname); + fclose(f); + unlink(usedname); + return false; + } + + if(time(NULL) > st.st_mtime + mesh->invitation_timeout) { + logger(mesh, MESHLINK_ERROR, "Peer %s tried to use an outdated invitation file %s\n", c->name, usedname); + fclose(f); + unlink(usedname); return false; }