42wim / matterbridge

bridge between mattermost, IRC, gitter, xmpp, slack, discord, telegram, rocketchat, twitch, ssh-chat, zulip, whatsapp, keybase, matrix, microsoft teams, nextcloud, mumble, vk and more with REST API (mattermost not required!)
Apache License 2.0
6.6k stars 615 forks source link

OOB Read at startup of the XMPP bridge #869

Closed GovanifY closed 5 years ago

GovanifY commented 5 years ago

Environment

Version: 1.15.2-dev

Operating system: 4.19.57-gentoo

go version go1.12.5 linux/amd64 79a006c8de311a7bbab540e62bd3fac998d415d5 ### Please describe the expected behavior. Being able to connect to XMPP without crashing ### Please describe the actual behavior.

A good ol' OOB read when splicing the Jid field

matrix@fujiwara ~ $ go/bin/matterbridge -debug -conf bridge-conf.toml 
[0000]  INFO main:         Enabling debug logging.
[0000]  INFO main:         Running version 1.15.2-dev 
[0000]  INFO main:         WARNING: THIS IS A DEVELOPMENT VERSION. Things may break.
[0000]  INFO router:       Parsing gateway gateway1
[0000]  INFO router:       Starting bridge: matrix.main 
[0000]  INFO matrix:       Connecting https://matrix.govanify.com
[0001]  INFO matrix:       Connection succeeded
[0001]  INFO matrix:       matrix.main: joining [something] (ID: [something]matrix.main)
[0001]  INFO router:       Starting bridge: xmpp.[something]
[0001]  INFO xmpp:         Connecting 
panic: runtime error: index out of range

goroutine 1 [running]:
github.com/42wim/matterbridge/bridge/xmpp.(*Bxmpp).createXMPP(0xc0001cb360, 0x4, 0x116c4ff)
        /home/matrix/go/src/github.com/42wim/matterbridge/bridge/xmpp/xmpp.go:111 +0x3e5
github.com/42wim/matterbridge/bridge/xmpp.(*Bxmpp).Connect(0xc0001cb360, 0x4, 0x117b161)
        /home/matrix/go/src/github.com/42wim/matterbridge/bridge/xmpp/xmpp.go:37 +0xf5
github.com/42wim/matterbridge/gateway.(*Router).Start(0xc0001cb270, 0x1400480, 0xc0003d65d0)
        /home/matrix/go/src/github.com/42wim/matterbridge/gateway/router.go:70 +0x3cd
main.main()
        /home/matrix/go/src/github.com/42wim/matterbridge/matterbridge.go:57 +0x49b

Any steps to reproduce the behavior?

Try my config, as long as you keep the Jid, from the look of the issue, I believe you can reproduce it.

Please add your configuration file

[xmpp.[something]]
Server="[something]"
#Jid your userid
Jid="govanify@jabber.fr"
Password="[something]"
Muc="[something]"
Nick="xmppbot"
RemoteNickFormat="[{PROTOCOL}] <{NICK}> "

[matrix.main]
#Server is your homeserver (eg https://matrix.org)
Server="https://matrix.govanify.com"

#login/pass of your bot.
#Use a dedicated user for this and not your own!
#Messages sent from this user will not be relayed to avoid loops.
Login="bridge_bot"
Password="[something]@[somethingelse]"

RemoteNickFormat="[{PROTOCOL}] <{NICK}> "

#Whether to send the homeserver suffix. eg ":matrix.org" in @username:matrix.org
#to other bridges, or only send "username".(true only sends username)
#OPTIONAL (default false)
NoHomeServerSuffix=false

[[gateway]]
name="gateway1"
enable=true

[[gateway.inout]]
account="matrix.main"
channel="[something]"

[[gateway.inout]]
account="xmpp.[something]"
channel="[something]"
42wim commented 5 years ago

Thanks for reporting, it's definitely an issue that needs to be fixed. But your configuration can't produce it, it'll only fail when you don't have a @ in the Jid

42wim commented 5 years ago

This should be fixed in dev build https://bintray.com/42wim/nightly/Matterbridge/v1.15.1-9-ge329f00#files

Could you let me know if you can still trigger it with this build? thanks!

GovanifY commented 5 years ago

@42wim hey, sorry, haven't been able to test out sooner. It seems the Jid field is not parsed at all on my machine:

[2019-09-07T20:48:41+01:00] FATAL main:         Starting gateway failed: Bridge xmpp.XXX failed to start: the Jid  doesn't contain an @