aboutsummaryrefslogtreecommitdiffstats
path: root/app
diff options
context:
space:
mode:
authorRobin Jarry <robin@jarry.cc>2023-10-11 08:45:18 +0200
committerRobin Jarry <robin@jarry.cc>2023-10-11 10:21:50 +0200
commit34650131379a4542538da63751a89588d2f2cc85 (patch)
treec90b08d51d6018637d1d71359bc5b9f15f2db42d /app
parentbc176bd61ba726351a489cabf4da16a47dc5ec3b (diff)
downloadaerc-34650131379a4542538da63751a89588d2f2cc85.tar.gz
app: fix nil pointer dereference on startup
Fix the following crash on startup: panic: runtime error: invalid memory address or nil pointer dereference [signal SIGSEGV: segmentation violation code=0x1 addr=0x80 pc=0x9e2314] goroutine 1 [running]: git.sr.ht/~rjarry/aerc/log.PanicHandler() git.sr.ht/~rjarry/aerc/log/panic-logger.go:51 +0x70f panic({0xae95a0, 0x119f9b0}) runtime/panic.go:890 +0x263 git.sr.ht/~rjarry/aerc/app.(*Aerc).SelectedAccount(0x8503cdd28?) git.sr.ht/~rjarry/aerc/app/aerc.go:384 +0x14 git.sr.ht/~rjarry/aerc/app.SelectedAccount(...) git.sr.ht/~rjarry/aerc/app/app.go:44 git.sr.ht/~rjarry/aerc/app.(*AccountView).isSelected(...) git.sr.ht/~rjarry/aerc/app/account.go:225 git.sr.ht/~rjarry/aerc/app.(*AccountView).UpdateStatus(0x850364380) git.sr.ht/~rjarry/aerc/app/account.go:127 +0x28 git.sr.ht/~rjarry/aerc/app.(*AccountView).SetStatus(0x850364380, {0x850243a50, 0x1, 0x0?}) git.sr.ht/~rjarry/aerc/app/account.go:123 +0x94 git.sr.ht/~rjarry/aerc/app.NewAccountView(0x8503d38c0, 0x85041bf80) git.sr.ht/~rjarry/aerc/app/account.go:111 +0x573 git.sr.ht/~rjarry/aerc/app.NewAerc({0xcab0c0?, 0x11fa3c8}, 0x850433860, 0xbf3040, {0xca75e8?, 0x11ca800}, 0x0?) git.sr.ht/~rjarry/aerc/app/aerc.go:91 +0x6ce git.sr.ht/~rjarry/aerc/app.Init(...) git.sr.ht/~rjarry/aerc/app/app.go:24 main.main() git.sr.ht/~rjarry/aerc/main.go:242 +0x52e There was two things very wrong: - Access of the global aerc pointer before it was initialized. - The host field of AccountView was left there and still accessed but never initialized. Replace the global aerc pointer with a real struct value. Update code accordingly. Remove the AccountView.host field which is now useless. Reported-by: Jens Grassel <jens@wegtam.com> Reported-by: Matěj Cepl <mcepl@cepl.eu> Fixes: bc176bd61ba7 ("app: export global functions") Signed-off-by: Robin Jarry <robin@jarry.cc> Tested-by: Moritz Poldrack <moritz@poldrack.dev>
Diffstat (limited to 'app')
-rw-r--r--app/account.go5
-rw-r--r--app/aerc.go28
-rw-r--r--app/app.go8
-rw-r--r--app/msglist.go3
-rw-r--r--app/status.go2
-rw-r--r--app/tabhost.go15
6 files changed, 19 insertions, 42 deletions
diff --git a/app/account.go b/app/account.go
index bcb5028a..c7abde6f 100644
--- a/app/account.go
+++ b/app/account.go
@@ -31,7 +31,6 @@ type AccountView struct {
dirlist DirectoryLister
labels []string
grid *ui.Grid
- host TabHost
tab *ui.Tab
msglist *MessageList
worker *types.Worker
@@ -125,7 +124,7 @@ func (acct *AccountView) SetStatus(setters ...state.SetStateFunc) {
func (acct *AccountView) UpdateStatus() {
if acct.isSelected() {
- acct.host.UpdateStatus()
+ UpdateStatus()
}
}
@@ -247,7 +246,7 @@ func (acct *AccountView) newStore(name string) *lib.MessageStore {
}
}, func() {
if uiConf.NewMessageBell {
- acct.host.Beep()
+ aerc.Beep()
}
},
acct.updateSplitView,
diff --git a/app/aerc.go b/app/aerc.go
index 1170a6f2..21430f80 100644
--- a/app/aerc.go
+++ b/app/aerc.go
@@ -51,12 +51,12 @@ type Choice struct {
Command []string
}
-func NewAerc(
+func (aerc *Aerc) Init(
crypto crypto.Provider,
cmd func([]string, *config.AccountConfig, *models.MessageInfo) error,
complete func(cmd string) ([]string, string), cmdHistory lib.History,
deferLoop chan struct{},
-) *Aerc {
+) {
tabs := ui.NewTabs(config.Ui)
statusbar := ui.NewStack(config.Ui)
@@ -74,18 +74,16 @@ func NewAerc(
grid.AddChild(tabs.TabContent).At(1, 0)
grid.AddChild(statusbar).At(2, 0)
- aerc := &Aerc{
- accounts: make(map[string]*AccountView),
- cmd: cmd,
- cmdHistory: cmdHistory,
- complete: complete,
- grid: grid,
- statusbar: statusbar,
- statusline: statusline,
- prompts: ui.NewStack(config.Ui),
- tabs: tabs,
- Crypto: crypto,
- }
+ aerc.accounts = make(map[string]*AccountView)
+ aerc.cmd = cmd
+ aerc.cmdHistory = cmdHistory
+ aerc.complete = complete
+ aerc.grid = grid
+ aerc.statusbar = statusbar
+ aerc.statusline = statusline
+ aerc.prompts = ui.NewStack(config.Ui)
+ aerc.tabs = tabs
+ aerc.Crypto = crypto
for _, acct := range config.Accounts {
view, err := NewAccountView(acct, deferLoop)
@@ -121,8 +119,6 @@ func NewAerc(
}
aerc.showConfigWarnings()
-
- return aerc
}
func (aerc *Aerc) showConfigWarnings() {
diff --git a/app/app.go b/app/app.go
index 80f940a3..73459cb8 100644
--- a/app/app.go
+++ b/app/app.go
@@ -13,7 +13,7 @@ import (
"github.com/ProtonMail/go-crypto/openpgp"
)
-var aerc *Aerc
+var aerc Aerc
func Init(
crypto crypto.Provider,
@@ -21,11 +21,11 @@ func Init(
complete func(cmd string) ([]string, string), history lib.History,
deferLoop chan struct{},
) {
- aerc = NewAerc(crypto, cmd, complete, history, deferLoop)
+ aerc.Init(crypto, cmd, complete, history, deferLoop)
}
-func Drawable() ui.DrawableInteractive { return aerc }
-func IPCHandler() ipc.Handler { return aerc }
+func Drawable() ui.DrawableInteractive { return &aerc }
+func IPCHandler() ipc.Handler { return &aerc }
func HandleMessage(msg types.WorkerMessage) { aerc.HandleMessage(msg) }
func CloseBackends() error { return aerc.CloseBackends() }
diff --git a/app/msglist.go b/app/msglist.go
index b60ae148..e57bfe9d 100644
--- a/app/msglist.go
+++ b/app/msglist.go
@@ -257,9 +257,6 @@ func (ml *MessageList) MouseEvent(localX int, localY int, event tcell.Event) {
if event, ok := event.(*tcell.EventMouse); ok {
switch event.Buttons() {
case tcell.Button1:
- if aerc == nil {
- return
- }
selectedMsg, ok := ml.Clicked(localX, localY)
if ok {
ml.Select(selectedMsg)
diff --git a/app/status.go b/app/status.go
index fdeede19..dbedea7e 100644
--- a/app/status.go
+++ b/app/status.go
@@ -47,7 +47,7 @@ func (status *StatusLine) Draw(ctx *ui.Context) {
msg = runewidth.FillRight(msg, ctx.Width())
style := status.uiConfig().GetStyle(config.STYLE_STATUSLINE_ERROR)
ctx.Printf(0, 0, style, "%s", msg)
- case aerc != nil && status.acct != nil:
+ case status.acct != nil:
data := state.NewDataSetter()
data.SetPendingKeys(aerc.pendingKeys)
data.SetState(&status.acct.state)
diff --git a/app/tabhost.go b/app/tabhost.go
deleted file mode 100644
index 9a206084..00000000
--- a/app/tabhost.go
+++ /dev/null
@@ -1,15 +0,0 @@
-package app
-
-import (
- "time"
-)
-
-type TabHost interface {
- BeginExCommand(cmd string)
- UpdateStatus()
- SetError(err string)
- PushStatus(text string, expiry time.Duration) *StatusMessage
- PushError(text string) *StatusMessage
- PushSuccess(text string) *StatusMessage
- Beep()
-}