aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlex Auvolat <alex@adnab.me>2020-04-05 12:31:35 +0200
committerAlex Auvolat <alex@adnab.me>2020-04-05 12:31:35 +0200
commit4d909fffd88c2a66094cfec6f43ac932113906b9 (patch)
treeb160bbb784b53521e4bef32402a50996faaca6bb
parentad8461491b35c739683971deff32a3203d0d7e5d (diff)
downloadeasybridge-4d909fffd88c2a66094cfec6f43ac932113906b9.tar.gz
easybridge-4d909fffd88c2a66094cfec6f43ac932113906b9.zip
Fix out of bounds error in user commands (the most stupid bug possible)
-rw-r--r--server.go19
1 files changed, 19 insertions, 0 deletions
diff --git a/server.go b/server.go
index 1868078..e87dad2 100644
--- a/server.go
+++ b/server.go
@@ -225,6 +225,10 @@ func handleTxnEvent(e *mxlib.Event) error {
func handleSystemMessage(mxid string, msg string) {
cmd := strings.Fields(msg)
+ if len(cmd) == 0 {
+ return
+ }
+
switch cmd[0] {
case "help":
ezbrSystemSend(mxid, "Welcome to Easybridge! Here is a list of available commands:")
@@ -246,6 +250,11 @@ func handleSystemMessage(mxid string, msg string) {
ezbrSystemSendf(mxid, "No account currently configured")
}
case "join":
+ if len(cmd) != 2 {
+ ezbrSystemSendf(mxid, "Usage: %s <protocol or account> <room id>", cmd[0])
+ return
+ }
+
account := findAccount(mxid, cmd[1])
if account != nil {
err := account.Conn.Join(connector.RoomID(cmd[2]))
@@ -256,6 +265,11 @@ func handleSystemMessage(mxid string, msg string) {
ezbrSystemSendf(mxid, "No account with name or using protocol %s", cmd[1])
}
case "query", "talk":
+ if len(cmd) != 2 {
+ ezbrSystemSendf(mxid, "Usage: %s <protocol or account> <user id>", cmd[0])
+ return
+ }
+
account := findAccount(mxid, cmd[1])
if account != nil {
quser := connector.UserID(cmd[2])
@@ -278,6 +292,11 @@ func handleSystemMessage(mxid string, msg string) {
ezbrSystemSendf(mxid, "No account with name or using protocol %s", cmd[1])
}
case "search":
+ if len(cmd) < 2 {
+ ezbrSystemSendf(mxid, "Usage: %s <protocol or account> <name>", cmd[0])
+ return
+ }
+
account := findAccount(mxid, cmd[1])
if account != nil {
rep, err := account.Conn.SearchForUsers(strings.Join(cmd[2:], " "))