From 6daf3f04fe51246f2bb7b0e3d369fec7d22d2d70 Mon Sep 17 00:00:00 2001 From: Guus Sliepen Date: Sat, 2 Apr 2022 15:39:08 +0200 Subject: [PATCH] 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. --- src/protocol_auth.c | 7 +++++++ 1 file changed, 7 insertions(+) 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); -- 2.20.1