Fix query/join with invalid IDs (for IRC)

This commit is contained in:
Alex 2020-02-17 21:19:28 +01:00
parent ad123342f7
commit f7ee64cdfe
2 changed files with 19 additions and 8 deletions

View file

@ -230,7 +230,12 @@ func handleSystemMessage(mxid string, msg string) {
} }
if account != nil { if account != nil {
quser := connector.UserID(cmd[2]) 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) quser_mxid, err := dbGetMxUser(account.Protocol, quser)
if err != nil { if err != nil {
ezbrSystemSendf(mxid, "%s", err) ezbrSystemSendf(mxid, "%s", err)

View file

@ -102,7 +102,10 @@ func (irc *IRC) User() UserID {
func (irc *IRC) checkRoomId(id RoomID) (string, error) { func (irc *IRC) checkRoomId(id RoomID) (string, error) {
x := strings.Split(string(id), "@") 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 "", fmt.Errorf("Invalid room ID: %s", id)
} }
return x[0], nil return x[0], nil
@ -110,7 +113,10 @@ func (irc *IRC) checkRoomId(id RoomID) (string, error) {
func (irc *IRC) checkUserId(id UserID) (string, error) { func (irc *IRC) checkUserId(id UserID) (string, error) {
x := strings.Split(string(id), "@") 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 "", fmt.Errorf("Invalid user ID: %s", id)
} }
return x[0], nil return x[0], nil
@ -149,6 +155,11 @@ func (irc *IRC) Join(roomId RoomID) error {
} }
func (irc *IRC) Invite(userId UserID, roomId RoomID) error { func (irc *IRC) Invite(userId UserID, roomId RoomID) error {
who, err := irc.checkUserId(userId)
if err != nil {
return err
}
if roomId == "" { if roomId == "" {
return nil return nil
} }
@ -158,11 +169,6 @@ func (irc *IRC) Invite(userId UserID, roomId RoomID) error {
return err return err
} }
who, err := irc.checkUserId(userId)
if err != nil {
return err
}
irc.conn.Cmd.Invite(ch, who) irc.conn.Cmd.Invite(ch, who)
return nil return nil
} }