From dc5c35758dca410350ff36f9bf5c9090236e6043 Mon Sep 17 00:00:00 2001 From: Robin Jarry Date: Mon, 31 Jul 2023 14:00:44 +0200 Subject: compose: fix panic when adding empty header with uppercase letters Running `:header Hello` causes a panic: panic: runtime error: invalid memory address or nil pointer dereference [signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0xa09328] goroutine 1 [running]: git.sr.ht/~rjarry/aerc/widgets.(*Composer).AddEditor git.sr.ht/~rjarry/aerc/widgets/compose.go:1302 git.sr.ht/~rjarry/aerc/commands/compose.Header.Execute git.sr.ht/~rjarry/aerc/commands/compose/header.go:83 git.sr.ht/~rjarry/aerc/commands.(*Commands).ExecuteCommand git.sr.ht/~rjarry/aerc/commands/commands.go:133 main.execCommand git.sr.ht/~rjarry/aerc/main.go:71 This is because addEditor() converts the header name to lowercase before updating the c.editors map. After this, c.editors[header] (with `header` containing uppercase letters) returns nil causes a nil pointer access. This is a side effect of splitting AddEditor into public and private functions. focusEditor also converts the argument to lowercase. Fix and simplify this. Only call focusEditor with whatever the user provided. Fixes: 11e5390fa0ac ("compose: implement embedded headers in editor") Reported-by: Koni Marti Signed-off-by: Robin Jarry Acked-by: Koni Marti --- widgets/compose.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/widgets/compose.go b/widgets/compose.go index c0f4af4f..fa88b0f0 100644 --- a/widgets/compose.go +++ b/widgets/compose.go @@ -1299,7 +1299,7 @@ func (c *Composer) AddEditor(header string, value string, appendHeader bool) err } value = c.addEditor(header, value, appendHeader) if value == "" { - c.focusEditor(c.editors[header].name) + c.focusEditor(header) } c.updateGrid() return nil -- cgit