Don't delete a suggestion when there is no suggestion selected - #5986
Open
Uzaaft wants to merge 1 commit into
Open
Don't delete a suggestion when there is no suggestion selected#5986Uzaaft wants to merge 1 commit into
Uzaaft wants to merge 1 commit into
Conversation
Deleting the last entry in the shell command history leaves the suggestions list focused but empty. An empty list reports its selected index as -1 (ListCursor.clampValue), and the delete keybinding passes that index straight to HandleDeleteSuggestion, which subscripts GetItems() with it. Pressing delete a second time panics and takes lazygit down with it. To reproduce: press ":" and run any command, press ":" again, tab into the suggestions, then press "d" twice. The handler two lines below already returns early on a -1, with a comment saying it should never happen. That index comes from lo.IndexOf, so this one never got the same scrutiny. We guard the binding the way ConfirmSuggestion directly above it is already guarded, with singleItemSelected. The key is then disabled with the usual reason instead of firing on an empty list
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This was found while fuzzing lazygit with https://github.com/antithesishq/bombadil, from which I found and reproduced a sequence of actions that manage to crash lazygit. Bad screenshot of the crash(will update):

PR Description
Deleting the last entry in the shell command history leaves the
suggestions list focused but empty. An empty list reports its selected
index as -1 (ListCursor.clampValue), and the delete keybinding passes
that index straight to HandleDeleteSuggestion, which subscripts
GetItems() with it. Pressing delete a second time panics and takes
lazygit down with it.
To reproduce: press ":" and run any command, press ":" again, tab into
the suggestions, then press "d" twice.
The handler two lines below already returns early on a -1, with a
comment saying it should never happen. That index comes from lo.IndexOf,
so this one never got the same scrutiny.
We guard the binding the way ConfirmSuggestion directly above it is
already guarded, with singleItemSelected. The key is then disabled with
the usual reason instead of firing on an empty list
Please check if the PR fulfills these requirements
go generate ./...)