From 4d2e290e8670ab07ae402a6e1320ef09144089f8 Mon Sep 17 00:00:00 2001 From: Guus Sliepen Date: Tue, 5 Nov 2019 20:46:58 +0100 Subject: [PATCH] Refuse invitees if we can't delete the invitation file. If the call to unlink() or a subsequent sync of the invitation directory fails, don't allow the invitee access, to prevent an invitation from being used twice. --- src/conf.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/conf.c b/src/conf.c index eea9c3dd..ca107b0a 100644 --- a/src/conf.c +++ b/src/conf.c @@ -866,7 +866,19 @@ bool invitation_read(meshlink_handle_t *mesh, const char *conf_subdir, const cha fclose(f); - unlink(used_path); + if(unlink(used_path)) { + logger(mesh, MESHLINK_ERROR, "Failed to unlink `%s': %s", path, strerror(errno)); + return false; + } + + snprintf(path, sizeof(path), "%s" SLASH "%s" SLASH "invitations", mesh->confbase, conf_subdir); + + if(!sync_path(path)) { + logger(mesh, MESHLINK_ERROR, "Failed to sync `%s': %s", path, strerror(errno)); + meshlink_errno = MESHLINK_ESTORAGE; + return false; + } + return true; } -- 2.39.5