aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlex Auvolat <alex@adnab.me>2020-02-17 21:19:28 +0100
committerAlex Auvolat <alex@adnab.me>2020-02-17 21:19:28 +0100
commitf7ee64cdfe599fce4bbc778c189538b26053d543 (patch)
treef933fe12d42a46c84c2515154a962a11dfaa725d
parentad123342f7ed0a0809b51189b59fe9a1ff2848ce (diff)
downloadeasybridge-f7ee64cdfe599fce4bbc778c189538b26053d543.tar.gz
easybridge-f7ee64cdfe599fce4bbc778c189538b26053d543.zip
Fix query/join with invalid IDs (for IRC)
-rw-r--r--appservice/server.go7
-rw-r--r--connector/irc/irc.go20
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
}