Skip to content

Commit

Permalink
[bugfix] Do not abort saving if the OTP counter is aborted (#2775)
Browse files Browse the repository at this point in the history
Fixes #2763

Signed-off-by: Dominik Schulz <[email protected]>
  • Loading branch information
dominikschulz authored Jan 19, 2024
1 parent 2f94aaf commit 5a98a02
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions internal/action/otp.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ func (s *Action) otp(ctx context.Context, name, qrf string, clip, pw, recurse bo
return s.otpHandleError(ctx, name, qrf, clip, pw, recurse, err)
}

outerCtx := ctx
ctx = config.WithMount(ctx, s.Store.MountPoint(name))
ctx, cancel := context.WithCancel(ctx)
defer cancel()
Expand Down Expand Up @@ -164,8 +165,9 @@ func (s *Action) otp(ctx context.Context, name, qrf string, clip, pw, recurse bo
}
counter++
_ = sec.Set("counter", strconv.Itoa(int(counter)))
if err := s.Store.Set(ctx, name, sec); err != nil {
out.Errorf(ctx, "Failed to persist counter value: %s", err)
// using outerCtx here because we want to save the counter even if the user cancels.
if err := s.Store.Set(outerCtx, name, sec); err != nil {
out.Errorf(outerCtx, "Failed to persist counter value: %s", err)
}
debug.Log("Saved counter as %d", counter)
}
Expand Down

0 comments on commit 5a98a02

Please sign in to comment.