Skip to content

Commit

Permalink
Fix nil pointer dereference when TCP listener is configured
Browse files Browse the repository at this point in the history
After 60526f6 (#31),
`irccat.tcp.Run(irccat.irc)` is called (if the config calls for it)
before, rather than after, `irccat.connectIRC()`, which changes
`irccat.irc` away from a nil pointer in the first place.  This pointer
is copied into the `irc` field of a TCPListener `l` by
`irccat.tcp.Run()`.

A panic won't actually happen until the TCP listener handles its first
message, if it ever comes, and in doing so passes the nil pointer
further down to `dispatcher.Send(l.irc, ...)`.

To fix, bring the call to `irccat.connectIRC()` forward again, to before
any listener setup is done at all.  This probably makes sense
stylistically too.
  • Loading branch information
edwinbalani authored and russss committed Apr 3, 2024
1 parent c4db8d0 commit 20f0ffb
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,13 @@ func main() {
signal.Notify(irccat.signals, os.Interrupt, syscall.SIGINT, syscall.SIGTERM)
go irccat.signalHandler()

err = irccat.connectIRC(*debug)

if err != nil {
log.Criticalf("Error connecting to IRC server: %s", err)
return
}

if viper.IsSet("tcp.listen") {
irccat.tcp, err = tcplistener.New()
if err != nil {
Expand All @@ -79,13 +86,6 @@ func main() {
irccat.tcp.Run(irccat.irc)
}

err = irccat.connectIRC(*debug)

if err != nil {
log.Criticalf("Error connecting to IRC server: %s", err)
return
}

if viper.IsSet("http") {
httplistener.New(irccat.irc)
}
Expand Down

0 comments on commit 20f0ffb

Please sign in to comment.