From: Guus Sliepen Date: Sat, 2 Apr 2022 13:39:08 +0000 (+0200) Subject: Improve handling invitation read errors. X-Git-Url: https://git.tinc-vpn.org/git/browse?a=commitdiff_plain;h=6daf3f04fe51246f2bb7b0e3d369fec7d22d2d70;p=tinc Improve handling invitation read errors. Fix a file descriptor leak when something goes wrong while reading an invitation file. Also check that we read it in full before committing. Found by cppcheck. --- diff --git a/src/protocol_auth.c b/src/protocol_auth.c index 19859b75..4d6c9911 100644 --- a/src/protocol_auth.c +++ b/src/protocol_auth.c @@ -296,6 +296,7 @@ static bool receive_invitation_sptps(void *handle, uint8_t type, const void *dat if(!fgets(buf, sizeof(buf), f)) { logger(DEBUG_ALWAYS, LOG_ERR, "Could not read invitation file %s\n", cookie); + fclose(f); return false; } @@ -336,6 +337,12 @@ static bool receive_invitation_sptps(void *handle, uint8_t type, const void *dat sptps_send_record(&c->sptps, 0, buf, result); } + if(!feof(f)) { + logger(DEBUG_ALWAYS, LOG_ERR, "Could not read invitation file %s\n", cookie); + fclose(f); + return false; + } + sptps_send_record(&c->sptps, 1, buf, 0); fclose(f); unlink(usedname);