From 0f41e99ea79f498b51cc5ade620e825fd43acbbe Mon Sep 17 00:00:00 2001 From: Denny Page Date: Sun, 14 Feb 2021 11:39:28 -0800 Subject: [PATCH 1/2] Treat an empty password as a fatal error for repository init. --- changelog/unreleased/issue-3214 | 8 ++++++++ cmd/restic/cmd_init.go | 10 +++++----- cmd/restic/global.go | 2 +- 3 files changed, 14 insertions(+), 6 deletions(-) create mode 100644 changelog/unreleased/issue-3214 diff --git a/changelog/unreleased/issue-3214 b/changelog/unreleased/issue-3214 new file mode 100644 index 000000000..d733b4176 --- /dev/null +++ b/changelog/unreleased/issue-3214 @@ -0,0 +1,8 @@ +Bugfix: Treat an empty password as a fatal error for repository init + +When attempting to initialize a new repository, if an empty password was +supplied, the repository would be created but the init command would return +an error with a stack trace. Now, if an empty password is provided, it is +treated as a fatal error, and no repository is created. + +https://github.com/restic/restic/issues/3214 diff --git a/cmd/restic/cmd_init.go b/cmd/restic/cmd_init.go index 1bdb2f208..bbab3711d 100644 --- a/cmd/restic/cmd_init.go +++ b/cmd/restic/cmd_init.go @@ -53,11 +53,6 @@ func runInit(opts InitOptions, gopts GlobalOptions, args []string) error { return err } - be, err := create(repo, gopts.extended) - if err != nil { - return errors.Fatalf("create repository at %s failed: %v\n", location.StripPassword(gopts.Repo), err) - } - gopts.password, err = ReadPasswordTwice(gopts, "enter password for new repository: ", "enter password again: ") @@ -65,6 +60,11 @@ func runInit(opts InitOptions, gopts GlobalOptions, args []string) error { return err } + be, err := create(repo, gopts.extended) + if err != nil { + return errors.Fatalf("create repository at %s failed: %v\n", location.StripPassword(gopts.Repo), err) + } + s := repository.New(be) err = s.Init(gopts.ctx, gopts.password, chunkerPolynomial) diff --git a/cmd/restic/global.go b/cmd/restic/global.go index 5843134ea..7f195d97b 100644 --- a/cmd/restic/global.go +++ b/cmd/restic/global.go @@ -364,7 +364,7 @@ func ReadPassword(opts GlobalOptions, prompt string) (string, error) { } if len(password) == 0 { - return "", errors.New("an empty password is not a password") + return "", errors.Fatal("an empty password is not a password") } return password, nil From 13730e3844e4f9d4976ed7a9bccb02e2adb0b8b1 Mon Sep 17 00:00:00 2001 From: Michael Eischer Date: Sun, 28 Feb 2021 00:40:52 +0100 Subject: [PATCH 2/2] Add link to pr to changelog --- changelog/unreleased/issue-3214 | 1 + 1 file changed, 1 insertion(+) diff --git a/changelog/unreleased/issue-3214 b/changelog/unreleased/issue-3214 index d733b4176..82c00291b 100644 --- a/changelog/unreleased/issue-3214 +++ b/changelog/unreleased/issue-3214 @@ -6,3 +6,4 @@ an error with a stack trace. Now, if an empty password is provided, it is treated as a fatal error, and no repository is created. https://github.com/restic/restic/issues/3214 +https://github.com/restic/restic/pull/3283