diff --git a/changelog/unreleased/issue-3214 b/changelog/unreleased/issue-3214 new file mode 100644 index 000000000..82c00291b --- /dev/null +++ b/changelog/unreleased/issue-3214 @@ -0,0 +1,9 @@ +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 +https://github.com/restic/restic/pull/3283 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