summaryrefslogtreecommitdiff
path: root/commands/account
diff options
context:
space:
mode:
authorRobin Jarry <robin@jarry.cc>2022-02-25 00:21:06 +0100
committerRobin Jarry <robin@jarry.cc>2022-02-25 13:56:53 +0100
commitc26d08103b327bd3f2470e542aa55ab354483347 (patch)
tree4c0567246916d676b71a4675c76a93a198add65f /commands/account
parent91ead11c47252ca8998fdad7b0770d6b8d07c987 (diff)
downloadaerc-c26d08103b327bd3f2470e542aa55ab354483347.zip
aerc: always check SelectedAccount return value
aerc.SelectedAccount() is used in lots of places. Most of them without checking the return value. In some cases, the currently selected tab is not related to any account (widget.Terminal for example). This can lead to unexpected crashes when accessing account specific configuration. When possible, return an error when no account is currently selected. If no error can be returned, fallback to non-account specific configuration. Signed-off-by: Robin Jarry <robin@jarry.cc> Reviewed-by: Koni Marti <koni.marti@gmail.com>
Diffstat (limited to 'commands/account')
-rw-r--r--commands/account/compose.go3
-rw-r--r--commands/account/view.go3
2 files changed, 6 insertions, 0 deletions
diff --git a/commands/account/compose.go b/commands/account/compose.go
index d4128db..1a62d0a 100644
--- a/commands/account/compose.go
+++ b/commands/account/compose.go
@@ -30,6 +30,9 @@ func (Compose) Execute(aerc *widgets.Aerc, args []string) error {
return err
}
acct := aerc.SelectedAccount()
+ if acct == nil {
+ return errors.New("No account selected")
+ }
if template == "" {
template = aerc.Config().Templates.NewMessage
}
diff --git a/commands/account/view.go b/commands/account/view.go
index 4f59d94..53ad267 100644
--- a/commands/account/view.go
+++ b/commands/account/view.go
@@ -26,6 +26,9 @@ func (ViewMessage) Execute(aerc *widgets.Aerc, args []string) error {
return errors.New("Usage: view-message")
}
acct := aerc.SelectedAccount()
+ if acct == nil {
+ return errors.New("No account selected")
+ }
if acct.Messages().Empty() {
return nil
}