From f7ee64cdfe599fce4bbc778c189538b26053d543 Mon Sep 17 00:00:00 2001 From: Alex Auvolat Date: Mon, 17 Feb 2020 21:19:28 +0100 Subject: Fix query/join with invalid IDs (for IRC) --- appservice/server.go | 7 ++++++- connector/irc/irc.go | 20 +++++++++++++------- 2 files changed, 19 insertions(+), 8 deletions(-) diff --git a/appservice/server.go b/appservice/server.go index da01e07..2585e2a 100644 --- a/appservice/server.go +++ b/appservice/server.go @@ -230,7 +230,12 @@ func handleSystemMessage(mxid string, msg string) { } if account != nil { quser := connector.UserID(cmd[2]) - account.Conn.Invite(quser, connector.RoomID("")) + err := account.Conn.Invite(quser, connector.RoomID("")) + if err != nil { + ezbrSystemSendf(mxid, "%s", err) + return + } + quser_mxid, err := dbGetMxUser(account.Protocol, quser) if err != nil { ezbrSystemSendf(mxid, "%s", err) diff --git a/connector/irc/irc.go b/connector/irc/irc.go index aa9723f..38aa79d 100644 --- a/connector/irc/irc.go +++ b/connector/irc/irc.go @@ -102,7 +102,10 @@ func (irc *IRC) User() UserID { func (irc *IRC) checkRoomId(id RoomID) (string, error) { x := strings.Split(string(id), "@") - if x[0][0] != '#' || (len(x) == 2 && x[1] != irc.server) { + if len(x) == 1 { + return "", fmt.Errorf("Please write whole room ID with server: %s@%s", id, irc.server) + } + if x[0][0] != '#' || len(x) != 2 || x[1] != irc.server { return "", fmt.Errorf("Invalid room ID: %s", id) } return x[0], nil @@ -110,7 +113,10 @@ func (irc *IRC) checkRoomId(id RoomID) (string, error) { func (irc *IRC) checkUserId(id UserID) (string, error) { x := strings.Split(string(id), "@") - if x[0][0] == '#' || (len(x) == 2 && x[1] != irc.server) { + if len(x) == 1 { + return "", fmt.Errorf("Please write whole user ID with server: %s@%s", id, irc.server) + } + if x[0][0] == '#' || len(x) != 2 || x[1] != irc.server { return "", fmt.Errorf("Invalid user ID: %s", id) } return x[0], nil @@ -149,6 +155,11 @@ func (irc *IRC) Join(roomId RoomID) error { } func (irc *IRC) Invite(userId UserID, roomId RoomID) error { + who, err := irc.checkUserId(userId) + if err != nil { + return err + } + if roomId == "" { return nil } @@ -158,11 +169,6 @@ func (irc *IRC) Invite(userId UserID, roomId RoomID) error { return err } - who, err := irc.checkUserId(userId) - if err != nil { - return err - } - irc.conn.Cmd.Invite(ch, who) return nil } -- cgit v1.2.3