From db3da4a27387bc0d692b5ee91d6bcccc8c498ab7 Mon Sep 17 00:00:00 2001 From: Daniel Silverstone Date: Sun, 13 Nov 2016 22:42:57 +0000 Subject: Fix information leak in rename command, enable the tests for that, disable a test which now shouldn't pass --- lib/gitano/command.lua | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-) (limited to 'lib') diff --git a/lib/gitano/command.lua b/lib/gitano/command.lua index 9694377..66be53e 100644 --- a/lib/gitano/command.lua +++ b/lib/gitano/command.lua @@ -655,19 +655,11 @@ local function builtin_rename_validate(config, repo, cmdline) log.error("Rename takes a repository and a new name for it") return false end - if not repo or repo.is_nascent then - log.error("Cannot rename", repo.name, "as it does not exit") - return false - end return true end local function builtin_rename_prep(config, repo, cmdline, context) local ctx, action, reason - -- Check 0, is the current repo nascent - if repo.is_nascent then - return "deny", "Cannot rename a repository which does not exist" - end -- Check 1, read current repo ctx = util.deep_copy(context) ctx.operation = "read" @@ -675,27 +667,32 @@ local function builtin_rename_prep(config, repo, cmdline, context) if action ~= "allow" then return action, reason end - -- Check 2, rename current repo + -- Check 2, is the current repo nascent + if repo.is_nascent then + return "deny", "Cannot rename a repository which does not exist" + end + -- Check 3, rename current repo ctx = util.deep_copy(context) ctx.operation = "renamerepo" action, reason = repo:run_lace(ctx) if action ~= "allow" then return action, reason end - -- Check 3, create new repo + -- Check 4, create new repo ctx = util.deep_copy(context) local newrepo, msg = repository.find(config, cmdline[3]) if not newrepo then return "deny", msg end - if not newrepo.is_nascent then - return "deny", "Destination location is in use" - end ctx.operation="createrepo" action, reason = newrepo:run_lace(ctx) if action ~= "allow" then return action, reason end + -- Check 5, does new repo already exist? + if not newrepo.is_nascent then + return "deny", "Destination location is in use" + end -- Okay, we could create, read, and destroy -- thus we can rename return "allow", "Passed all checks, can rename" -- cgit v1.2.1