From 96021fe85b0ad03029d2216942d6adb4b3c7cb7a Mon Sep 17 00:00:00 2001 From: Elle Mouton Date: Wed, 31 Aug 2022 15:31:49 +0200 Subject: [PATCH] cmd+docs: fix cap out of range error in profile command If `lncli profile remove` is called when there are no existing profiles, it will cause a "cap out of range" panic. So in this commit, a length check is added to avoid this. --- cmd/lncli/cmd_profile.go | 4 ++++ docs/release-notes/release-notes-0.16.0.md | 3 +++ 2 files changed, 7 insertions(+) diff --git a/cmd/lncli/cmd_profile.go b/cmd/lncli/cmd_profile.go index e1983171a..428daede8 100644 --- a/cmd/lncli/cmd_profile.go +++ b/cmd/lncli/cmd_profile.go @@ -199,6 +199,10 @@ func profileRemove(ctx *cli.Context) error { return fmt.Errorf("name argument missing") } + if len(f.Profiles) == 0 { + return fmt.Errorf("there are no existing profiles") + } + // Create a copy of all profiles but don't include the one to delete. newProfiles := make([]*profileEntry, 0, len(f.Profiles)-1) for _, p := range f.Profiles { diff --git a/docs/release-notes/release-notes-0.16.0.md b/docs/release-notes/release-notes-0.16.0.md index 107c3d9ca..76fd5a73c 100644 --- a/docs/release-notes/release-notes-0.16.0.md +++ b/docs/release-notes/release-notes-0.16.0.md @@ -57,6 +57,9 @@ minimum version needed to build the project. * [Fix](https://github.com/lightningnetwork/lnd/pull/6858) command line argument parsing for `lncli sendpayment`. +* [Fix](https://github.com/lightningnetwork/lnd/pull/6875) mapslice cap out of + range error that occurs if the number of profiles is zero. + ## Code Health * [test: use `T.TempDir` to create temporary test