Browse Source

Fix nil pointer dereference when TCP listener is configured

After 60526f60a8 (#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.
master
Edwin Balani 2 months ago
parent
commit
20f0ffbe10
1 changed files with 7 additions and 7 deletions
  1. 7
    7
      main.go

+ 7
- 7
main.go View File

70
 	signal.Notify(irccat.signals, os.Interrupt, syscall.SIGINT, syscall.SIGTERM)
70
 	signal.Notify(irccat.signals, os.Interrupt, syscall.SIGINT, syscall.SIGTERM)
71
 	go irccat.signalHandler()
71
 	go irccat.signalHandler()
72
 
72
 
73
+	err = irccat.connectIRC(*debug)
74
+
75
+	if err != nil {
76
+		log.Criticalf("Error connecting to IRC server: %s", err)
77
+		return
78
+	}
79
+
73
 	if viper.IsSet("tcp.listen") {
80
 	if viper.IsSet("tcp.listen") {
74
 		irccat.tcp, err = tcplistener.New()
81
 		irccat.tcp, err = tcplistener.New()
75
 		if err != nil {
82
 		if err != nil {
79
 		irccat.tcp.Run(irccat.irc)
86
 		irccat.tcp.Run(irccat.irc)
80
 	}
87
 	}
81
 
88
 
82
-	err = irccat.connectIRC(*debug)
83
-
84
-	if err != nil {
85
-		log.Criticalf("Error connecting to IRC server: %s", err)
86
-		return
87
-	}
88
-
89
 	if viper.IsSet("http") {
89
 	if viper.IsSet("http") {
90
 		httplistener.New(irccat.irc)
90
 		httplistener.New(irccat.irc)
91
 	}
91
 	}

Loading…
Cancel
Save