gorcon / rcon

Source RCON Protocol implementation in Go.
MIT License
85 stars 8 forks source link

`panic: runtime error: makeslice: len out of range` in `rcon.Dial` #5

Closed cezarmathe closed 2 years ago

cezarmathe commented 2 years ago

My usage: https://github.com/cezarmathe/stevebot/blob/ac309b0f0555ec6f87572caf5f42b92180926789/cmd/stevebot2/main.go#L72

My logs:

1.6525867005549443e+09  info    stevebot2/main.go:55    hello, this is stevebot2
1.6525867005552022e+09  debug   stevebot2/main.go:64    main config {"value": {"DiscordToken":"redacted","RconAddress":"redacted:25565","RconPassword":"redacted","Bot":{"CommandPrefix":"~"},"Steve":{"AllowedCommands":["help","seed","whitelist"]}}}
panic: runtime error: makeslice: len out of range

goroutine 1 [running]:
github.com/gorcon/rcon.(*Conn).auth(0xc00001e280, {0xc00002604e?, 0xc00002a04d?})
    /path/to/my/go/root/pkg/mod/github.com/gorcon/rcon@v1.3.1/rcon.go:202 +0x227
github.com/gorcon/rcon.Dial({0xc00002a04d, 0x13}, {0xc00002604e, 0x28}, {0x0, 0x0, 0x1?})
    /path/to/my/go/root/pkg/mod/github.com/gorcon/rcon@v1.3.1/rcon.go:112 +0x196
main.main()
    /path/to/project/root/stevebot/cmd/stevebot2/main.go:72 +0x668

I've identified that this issue comes from https://github.com/gorcon/rcon/blob/79dc2ba55137b18eff9cb2531b38afcc25a3989a/rcon.go#L202

outdead commented 2 years ago

Thanks for you issue!

Tell me please what game causes this panic?

outdead commented 2 years ago

I see, it is Minecraft. I'll check

outdead commented 2 years ago

Try v1.3.2.

cezarmathe commented 2 years ago

I get the same issue:

1.6526817170475295e+09  info    stevebot2/main.go:55    hello, this is stevebot2
1.6526817170477707e+09  debug   stevebot2/main.go:64    main config {"value": {"DiscordToken":"redacted","RconAddress":"redacted:25565","RconPassword":"redacted","Bot":{"CommandPrefix":"~"},"Steve":{"AllowedCommands":["help","seed","whitelist"]}}}
panic: runtime error: makeslice: len out of range

goroutine 1 [running]:
github.com/gorcon/rcon.(*Conn).auth(0xc000292000, {0xc00002604e?, 0xc00002a04d?})
    /redacted/pkg/mod/github.com/gorcon/rcon@v1.3.2/rcon.go:206 +0x22a
github.com/gorcon/rcon.Dial({0xc00002a04d, 0x13}, {0xc00002604e, 0x28}, {0x0, 0x0, 0x1?})
    /redacted/pkg/mod/github.com/gorcon/rcon@v1.3.2/rcon.go:112 +0x196
main.main()
    /redacted/stevebot/cmd/stevebot2/main.go:72 +0x668

It could possibly be that the response size is 0 and it's a runtime error to make a slice of len 0.

https://github.com/gorcon/rcon/commit/dac804a9e0bb97c89921e1441c92536f48ed0bdf#diff-54f05da6f66887a7de9daf89b89aa66cebefbccc3a9dbbb6c8f3006eba3c1bbfR186-R189

On the side, though, I noticed that my server was not actually running. I haven't tested this with a running server yet, but I'll let you know how it goes - I'm quite confident it will work okay.

So this is more of an issue regarding what happens if the server is down. It's pretty weird, though, as I would've expected to get an error regarding the TCP connection and I noticed that there is error handling logic for that. The issue is on my end probably. I'll post an update when I test with a running server.

UPDATE 1: Same issue with the server running, but I get 2022/05/16 09:26:09 Failed to connect to RCON serverrcon: authentication failed in my server logs.

UPDATE 2: I just noticed that I was using the game port instead of the rcon port. I fixed that and I no longer have this issue.

outdead commented 2 years ago

I added new error message instead this panic. Can you check this with wrong port on v1.3.3 please? I have no Minecraft server now and can reproduce it only on test mock.

cezarmathe commented 2 years ago

{"error": "rcon: response from not rcon server"}

haha, yes, this is great!