commit b6fbac7
Hubert Hirtz
·
2021-03-05 17:56:06 +0000 UTC
parent 2cb8cf5
Fix segmentation fault when the server is down
1 files changed,
+13,
-8
M
app.go
M
app.go
+13,
-8
1@@ -161,21 +161,25 @@ func (app *App) connect() {
2
3 func (app *App) tryConnect() (err error) {
4 addr := app.cfg.Addr
5- serverName := app.cfg.Addr
6- if i := strings.IndexByte(app.cfg.Addr, ':'); i >= 0 {
7- serverName = app.cfg.Addr[:i]
8- } else {
9- addr = app.cfg.Addr + ":6697"
10+ host, port, err := net.SplitHostPort(addr)
11+ if err != nil {
12+ return err
13+ }
14+ if port == "" {
15+ if app.cfg.NoTLS {
16+ port = "6667"
17+ } else {
18+ port = "6697"
19+ }
20 }
21
22- peerAddr, err := net.ResolveTCPAddr("tcp", addr)
23+ peerAddr, err := net.ResolveTCPAddr("tcp", net.JoinHostPort(host, port))
24 if err != nil {
25 return
26 }
27
28 tcpConn, err := net.DialTCP("tcp", nil, peerAddr)
29 if err != nil {
30- tcpConn.Close()
31 return
32 }
33 if err = tcpConn.SetKeepAlivePeriod(1 * time.Minute); err != nil {
34@@ -190,7 +194,8 @@ func (app *App) tryConnect() (err error) {
35 var conn net.Conn = tcpConn
36 if !app.cfg.NoTLS {
37 conn = tls.Client(conn, &tls.Config{
38- ServerName: serverName,
39+ ServerName: host,
40+ NextProtos: []string{"irc"},
41 })
42 }
43