commit fe9bc1a

Jeff Knapp  ·  2022-02-16 17:09:08 +0000 UTC
parent f6a5181
Fix segfault on /mode x

Return an error instead of segfaulting when handling /mode x where x
is a string that starts without + - or #
1 files changed,  +10, -1
+10, -1
 1@@ -1,6 +1,7 @@
 2 package senpai
 3 
 4 import (
 5+	"errors"
 6 	"fmt"
 7 	"sort"
 8 	"strconv"
 9@@ -374,11 +375,19 @@ func commandDoNick(app *App, args []string) (err error) {
10 }
11 
12 func commandDoMode(app *App, args []string) (err error) {
13-	if strings.HasPrefix(args[0], "+") || strings.HasPrefix(args[0], "-") {
14+	hasModePrefix := strings.HasPrefix(args[0], "+") || strings.HasPrefix(args[0], "-")
15+	hasChanPrefix := strings.HasPrefix(args[0], "#")
16+
17+	if !hasModePrefix && !hasChanPrefix {
18+		return errors.New("invalid argument")
19+	}
20+
21+	if hasModePrefix {
22 		// if we do eg /MODE +P, automatically insert the current channel: /MODE #<current-chan> +P
23 		_, channel := app.win.CurrentBuffer()
24 		args = append([]string{channel}, args...)
25 	}
26+
27 	channel := args[0]
28 	flags := args[1]
29 	modeArgs := args[2:]