compose: avoid deadlock when adding new header

AddEditor acquires the lock and calls FocusEditor which also attempts to
acquire it. Since the lock is not re-entrant, it ends in deadlock.

Add an internal focusEditor fonction that does not acquire the lock.

Fixes: bf2bf8c242 ("compose: prevent out of bounds access")
Reported-by: Moritz Poldrack <moritz@poldrack.dev>
Signed-off-by: Robin Jarry <robin@jarry.cc>
Tested-by: Thomas Vigouroux <thomas.vigouroux@protonmail.com>
This commit is contained in:
Robin Jarry 2022-10-10 11:32:12 +02:00
parent 2eef2adfbd
commit 34014d3cee
1 changed files with 5 additions and 1 deletions

View File

@ -958,6 +958,10 @@ func (c *Composer) NextField() {
func (c *Composer) FocusEditor(editor string) {
c.Lock()
defer c.Unlock()
c.focusEditor(editor)
}
func (c *Composer) focusEditor(editor string) {
editor = strings.ToLower(editor)
c.focusable[c.focused].Focus(false)
for i, f := range c.focusable {
@ -1007,7 +1011,7 @@ func (c *Composer) AddEditor(header string, value string, appendHeader bool) {
editor.storeValue()
}
if value == "" {
c.FocusEditor(c.editors[header].name)
c.focusEditor(c.editors[header].name)
}
c.updateGrid()
}