Browse Source

Various crash fixes, and little cleanups for safety

tags/v0.5.0
Daniel Oaks 7 years ago
parent
commit
c3174bb648
5 changed files with 59 additions and 14 deletions
  1. 2
    0
      CHANGELOG.md
  2. 10
    0
      DEVELOPING.md
  3. 8
    2
      irc/client.go
  4. 4
    2
      irc/modes.go
  5. 35
    10
      irc/server.go

+ 2
- 0
CHANGELOG.md View File

@@ -17,6 +17,8 @@ New release of Oragono!
17 17
 ### Removed
18 18
 
19 19
 ### Fixed
20
+* Fixed crash when using STATUSMSG-like messaging.
21
+* Fixed crash with gIRC-Go ircmsg library we depend on.
20 22
 
21 23
 
22 24
 ## [0.4.0] - 2016-11-03

+ 10
- 0
DEVELOPING.md View File

@@ -0,0 +1,10 @@
1
+# Developing Oragono
2
+
3
+Most development happens on the `develop` branch, which is occasionally rebased + merged into `master` when it's not incredibly broken.
4
+
5
+The intent is to keep `master` relatively stable.
6
+
7
+
8
+## Fuzzing
9
+
10
+Fuzzing can be useful. We don't have testing done inside the IRCd itself, but this fuzzer I've written works alright and has helped shake out various bugs: [irc_fuzz.py](https://gist.github.com/DanielOaks/63ae611039cdf591dfa4) 

+ 8
- 2
irc/client.go View File

@@ -20,7 +20,7 @@ import (
20 20
 const (
21 21
 	IDLE_TIMEOUT        = time.Minute + time.Second*30 // how long before a client is considered idle
22 22
 	QUIT_TIMEOUT        = time.Minute                  // how long after idle before a client is kicked
23
-	IdentTimeoutSeconds = 8
23
+	IdentTimeoutSeconds = 5
24 24
 )
25 25
 
26 26
 var (
@@ -157,7 +157,11 @@ func (client *Client) run() {
157 157
 
158 158
 		cmd, exists := Commands[msg.Command]
159 159
 		if !exists {
160
-			client.Send(nil, client.server.name, ERR_UNKNOWNCOMMAND, client.nick, msg.Command, "Unknown command")
160
+			if len(msg.Command) > 0 {
161
+				client.Send(nil, client.server.name, ERR_UNKNOWNCOMMAND, client.nick, msg.Command, "Unknown command")
162
+			} else {
163
+				client.Send(nil, client.server.name, ERR_UNKNOWNCOMMAND, client.nick, "lastcmd", "No command given")
164
+			}
161 165
 			continue
162 166
 		}
163 167
 
@@ -463,6 +467,8 @@ func (client *Client) Send(tags *map[string]ircmsg.TagValue, prefix string, comm
463 467
 		// try not to fail quietly - especially useful when running tests, as a note to dig deeper
464 468
 		// log.Println("Error assembling message:")
465 469
 		// spew.Dump(message)
470
+		// debug.PrintStack()
471
+
466 472
 		message = ircmsg.MakeMessage(nil, client.server.name, ERR_UNKNOWNERROR, "*", "Error assembling message for sending")
467 473
 		line, _ := message.Line()
468 474
 		client.socket.Write(line)

+ 4
- 2
irc/modes.go View File

@@ -207,7 +207,7 @@ var (
207 207
 func SplitChannelMembershipPrefixes(target string) (prefixes string, name string) {
208 208
 	name = target
209 209
 	for {
210
-		if len(name) == 0 || strings.Contains("~&@%+", string(name[0])) {
210
+		if len(name) > 0 && strings.Contains("~&@%+", string(name[0])) {
211 211
 			prefixes += string(name[0])
212 212
 			name = name[1:]
213 213
 		} else {
@@ -257,7 +257,9 @@ func umodeHandler(server *Server, client *Client, msg ircmsg.IrcMessage) bool {
257 257
 	target := server.clients.Get(nickname)
258 258
 
259 259
 	if err != nil || target == nil {
260
-		client.Send(nil, server.name, ERR_NOSUCHNICK, client.nick, msg.Params[0], "No such nick")
260
+		if len(msg.Params[0]) > 0 {
261
+			client.Send(nil, server.name, ERR_NOSUCHNICK, client.nick, msg.Params[0], "No such nick")
262
+		}
261 263
 		return false
262 264
 	}
263 265
 

+ 35
- 10
irc/server.go View File

@@ -354,7 +354,7 @@ func (server *Server) Run() {
354 354
 				if isBanned {
355 355
 					banMessage := fmt.Sprintf(bannedFromServerBytes, info.Reason)
356 356
 					if info.Time != nil {
357
-						banMessage += fmt.Sprintf(" [%s]", info.Time.Length.String())
357
+						banMessage += fmt.Sprintf(" [%s]", info.Time.Duration.String())
358 358
 					}
359 359
 					conn.Conn.Write([]byte(banMessage))
360 360
 					conn.Conn.Close()
@@ -698,7 +698,9 @@ func joinHandler(server *Server, client *Client, msg ircmsg.IrcMessage) bool {
698 698
 	for i, name := range channels {
699 699
 		casefoldedName, err := CasefoldChannel(name)
700 700
 		if err != nil {
701
-			client.Send(nil, server.name, ERR_NOSUCHCHANNEL, client.nick, name, "No such channel")
701
+			if len(name) > 0 {
702
+				client.Send(nil, server.name, ERR_NOSUCHCHANNEL, client.nick, name, "No such channel")
703
+			}
702 704
 			continue
703 705
 		}
704 706
 
@@ -734,7 +736,9 @@ func partHandler(server *Server, client *Client, msg ircmsg.IrcMessage) bool {
734 736
 		channel := server.channels.Get(casefoldedChannelName)
735 737
 
736 738
 		if err != nil || channel == nil {
737
-			client.Send(nil, server.name, ERR_NOSUCHCHANNEL, client.nick, chname, "No such channel")
739
+			if len(chname) > 0 {
740
+				client.Send(nil, server.name, ERR_NOSUCHCHANNEL, client.nick, chname, "No such channel")
741
+			}
738 742
 			continue
739 743
 		}
740 744
 
@@ -748,7 +752,9 @@ func topicHandler(server *Server, client *Client, msg ircmsg.IrcMessage) bool {
748 752
 	name, err := CasefoldChannel(msg.Params[0])
749 753
 	channel := server.channels.Get(name)
750 754
 	if err != nil || channel == nil {
751
-		client.Send(nil, server.name, ERR_NOSUCHCHANNEL, client.nick, msg.Params[0], "No such channel")
755
+		if len(msg.Params[0]) > 0 {
756
+			client.Send(nil, server.name, ERR_NOSUCHCHANNEL, client.nick, msg.Params[0], "No such channel")
757
+		}
752 758
 		return false
753 759
 	}
754 760
 
@@ -774,6 +780,11 @@ func privmsgHandler(server *Server, client *Client, msg ircmsg.IrcMessage) bool
774 780
 		prefixes, targetString := SplitChannelMembershipPrefixes(targetString)
775 781
 		lowestPrefix := GetLowestChannelModePrefix(prefixes)
776 782
 
783
+		// eh, no need to notify them
784
+		if len(targetString) < 1 {
785
+			continue
786
+		}
787
+
777 788
 		target, err := CasefoldChannel(targetString)
778 789
 		if err == nil {
779 790
 			channel := server.channels.Get(target)
@@ -786,7 +797,9 @@ func privmsgHandler(server *Server, client *Client, msg ircmsg.IrcMessage) bool
786 797
 			target, err = CasefoldName(targetString)
787 798
 			user := server.clients.Get(target)
788 799
 			if err != nil || user == nil {
789
-				client.Send(nil, server.name, ERR_NOSUCHNICK, target, "No such nick")
800
+				if len(target) > 0 {
801
+					client.Send(nil, server.name, ERR_NOSUCHNICK, target, "No such nick")
802
+				}
790 803
 				continue
791 804
 			}
792 805
 			if !user.capabilities[MessageTags] {
@@ -832,6 +845,11 @@ func whoisHandler(server *Server, client *Client, msg ircmsg.IrcMessage) bool {
832 845
 		masksString = msg.Params[0]
833 846
 	}
834 847
 
848
+	if len(strings.TrimSpace(masksString)) < 1 {
849
+		client.Send(nil, server.name, ERR_UNKNOWNERROR, client.nick, msg.Command, "No masks given")
850
+		return false
851
+	}
852
+
835 853
 	if client.flags[Operator] {
836 854
 		masks := strings.Split(masksString, ",")
837 855
 		for _, mask := range masks {
@@ -964,7 +982,6 @@ func operHandler(server *Server, client *Client, msg ircmsg.IrcMessage) bool {
964 982
 	err = ComparePassword(hash, password)
965 983
 
966 984
 	if (hash == nil) || (err != nil) {
967
-		fmt.Println("2", hash)
968 985
 		client.Send(nil, server.name, ERR_PASSWDMISMATCH, client.nick, "Password incorrect")
969 986
 		return true
970 987
 	}
@@ -1392,7 +1409,9 @@ func listHandler(server *Server, client *Client, msg ircmsg.IrcMessage) bool {
1392 1409
 			casefoldedChname, err := CasefoldChannel(chname)
1393 1410
 			channel := server.channels.Get(casefoldedChname)
1394 1411
 			if err != nil || channel == nil || (!client.flags[Operator] && channel.flags[Secret]) {
1395
-				client.Send(nil, server.name, ERR_NOSUCHCHANNEL, client.nick, chname, "No such channel")
1412
+				if len(chname) > 0 {
1413
+					client.Send(nil, server.name, ERR_NOSUCHCHANNEL, client.nick, chname, "No such channel")
1414
+				}
1396 1415
 				continue
1397 1416
 			}
1398 1417
 			client.RplList(channel)
@@ -1445,7 +1464,9 @@ func namesHandler(server *Server, client *Client, msg ircmsg.IrcMessage) bool {
1445 1464
 		casefoldedChname, err := CasefoldChannel(chname)
1446 1465
 		channel := server.channels.Get(casefoldedChname)
1447 1466
 		if err != nil || channel == nil {
1448
-			client.Send(nil, server.name, ERR_NOSUCHCHANNEL, client.nick, chname, "No such channel")
1467
+			if len(chname) > 0 {
1468
+				client.Send(nil, server.name, ERR_NOSUCHCHANNEL, client.nick, chname, "No such channel")
1469
+			}
1449 1470
 			continue
1450 1471
 		}
1451 1472
 		channel.Names(client)
@@ -1545,13 +1566,17 @@ func whowasHandler(server *Server, client *Client, msg ircmsg.IrcMessage) bool {
1545 1566
 	for _, nickname := range nicknames {
1546 1567
 		results := server.whoWas.Find(nickname, count)
1547 1568
 		if len(results) == 0 {
1548
-			client.Send(nil, server.name, ERR_WASNOSUCHNICK, client.nick, nickname, "There was no such nickname")
1569
+			if len(nickname) > 0 {
1570
+				client.Send(nil, server.name, ERR_WASNOSUCHNICK, client.nick, nickname, "There was no such nickname")
1571
+			}
1549 1572
 		} else {
1550 1573
 			for _, whoWas := range results {
1551 1574
 				client.Send(nil, server.name, RPL_WHOWASUSER, client.nick, whoWas.nickname, whoWas.username, whoWas.hostname, "*", whoWas.realname)
1552 1575
 			}
1553 1576
 		}
1554
-		client.Send(nil, server.name, RPL_ENDOFWHOWAS, client.nick, nickname, "End of WHOWAS")
1577
+		if len(nickname) > 0 {
1578
+			client.Send(nil, server.name, RPL_ENDOFWHOWAS, client.nick, nickname, "End of WHOWAS")
1579
+		}
1555 1580
 	}
1556 1581
 	return false
1557 1582
 }

Loading…
Cancel
Save