cmd/loop: require explicit 'y' confirmation on reservation new

The reservation new command printed the prepay cost and asked the user
to confirm with 'y/n'. The implementation read the answer with
fmt.Scanln(&answer) and treated only the literal 'n' as a 'no'. The
return value was discarded, so:

  - On EOF / closed stdin (CI pipelines, automated wrappers, terminal
    disconnect) Scanln returned an error and answer remained the empty
    string, which is not 'n', so the command proceeded and paid the
    LN prepayment with no user confirmation.
  - The case-sensitive 'n' check also accepted 'N', 'no', 'yes', 'Y',
    or any other string as a 'yes'.

Match the convention used by the rest of the loop CLI: only continue
when the user typed exactly 'y' (or 'Y'), and treat any read error as
'no'.
This commit is contained in:
Slyghtning 2026-05-11 16:04:23 +02:00
parent 800dae0750
commit 3c495a2a5c
No known key found for this signature in database
GPG key ID: F82D456EA023C9BF

View file

@ -4,6 +4,7 @@ import (
"context"
"errors"
"fmt"
"strings"
"github.com/lightninglabs/loop/looprpc"
"github.com/urfave/cli/v3"
@ -97,8 +98,9 @@ func newReservation(ctx context.Context, cmd *cli.Command) error {
fmt.Printf("CONTINUE RESERVATION? (y/n): ")
var answer string
fmt.Scanln(&answer)
if answer == "n" {
if _, err := fmt.Scanln(&answer); err != nil ||
!strings.EqualFold(answer, "y") {
return nil
}