fix: index out of bounds in parseHost

This commit is contained in:
DarkCat09 2024-07-02 18:57:42 +04:00
parent 68a5f0d2e9
commit af3d980252
Signed by: DarkCat09
GPG key ID: 0A26CD5B3345D6E3

View file

@ -113,15 +113,17 @@ func handler(ctx *fasthttp.RequestCtx) {
func parseHost(host []byte, https bool) ([]byte, []byte) { func parseHost(host []byte, https bool) ([]byte, []byte) {
idx := bytes.LastIndex(host, []byte(":")) idx := bytes.LastIndex(host, []byte(":"))
var port []byte var resHost, port []byte
if idx != -1 { if idx != -1 {
resHost = host[:idx]
port = host[idx+1:] port = host[idx+1:]
} else { } else {
resHost = host
if https { if https {
port = []byte("443") port = []byte("443")
} else { } else {
port = []byte("80") port = []byte("80")
} }
} }
return host[:idx], port return resHost, port
} }