Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Crash in replaceAction (discord) #1120

Closed
qaisjp opened this issue Apr 25, 2020 · 0 comments · Fixed by #1121
Closed

Crash in replaceAction (discord) #1120

qaisjp opened this issue Apr 25, 2020 · 0 comments · Fixed by #1121
Assignees
Labels

Comments

@qaisjp
Copy link
Collaborator

qaisjp commented Apr 25, 2020

Describe the bug
replaceAction checks if a string has the prefix _ and the suffix _. A string of length 1, "_", passes this check.

To Reproduce
Steps to reproduce the behavior, on Discord type this:

  1. /me hello
  2. Click on "Edit message"
  3. Change _hello_ to just _
  4. panic

Expected behavior

No panic

Screenshots/debug logs

panic: runtime error: slice bounds out of range [1:0]

goroutine 206785 [running]:
github.com/42wim/matterbridge/bridge/discord.(*Bdiscord).replaceAction(...)
        /home/qaisjp/apps/matterbridge/bridge/discord/helpers.go:192
github.com/42wim/matterbridge/bridge/discord.(*Bdiscord).messageCreate(0xc000409110, 0xc0004d28c0, 0xc0024db7e0)
        /home/qaisjp/apps/matterbridge/bridge/discord/handlers.go:122 +0xbe5
github.com/matterbridge/discordgo.messageCreateEventHandler.Handle(0xc0005bc000, 0xc0004d28c0, 0x1841320, 0xc0024db7e0)
        /home/qaisjp/apps/matterbridge/vendor/github.com/matterbridge/discordgo/eventhandlers.go:497 +0x57
created by github.com/matterbridge/discordgo.(*Session).handle
        /home/qaisjp/apps/matterbridge/vendor/github.com/matterbridge/discordgo/event.go:171 +0x10e

Environment (please complete the following information):
Version based on 1.17.1, with some PRs cherry-picked. But replaceAction hasn't changed in months.

linux

Additional context
Line 191 needs length check to fix this

func (b *Bdiscord) replaceAction(text string) (string, bool) {
if strings.HasPrefix(text, "_") && strings.HasSuffix(text, "_") {
return text[1 : len(text)-1], true
}
return text, false
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant