diff options
author | Robin Jarry <robin@jarry.cc> | 2022-10-10 11:32:12 +0200 |
---|---|---|
committer | Robin Jarry <robin@jarry.cc> | 2022-10-11 14:50:34 +0200 |
commit | 34014d3ceeebe8a9c131213fa56d1977fbc26b4a (patch) | |
tree | 4c8bdb975ccf8a052463f7316110c647be7e1994 | |
parent | 2eef2adfbdc4b1c0093021ad0f4ee3825f275906 (diff) | |
download | aerc-34014d3ceeebe8a9c131213fa56d1977fbc26b4a.tar.gz |
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: bf2bf8c242cb ("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>
-rw-r--r-- | widgets/compose.go | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/widgets/compose.go b/widgets/compose.go index 0c26d070..9b8b30cb 100644 --- a/widgets/compose.go +++ b/widgets/compose.go @@ -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() } |