bittorrent: validate port != 0 for announces

This commit is contained in:
Leo Balduf 2018-02-13 10:13:57 +01:00
parent a8bc51ba1d
commit b19f7115df

View file

@ -9,9 +9,16 @@ import (
// ErrInvalidIP indicates an invalid IP for an Announce.
var ErrInvalidIP = ClientError("invalid IP")
// ErrInvalidPort indicates an invalid Port for an Announce.
var ErrInvalidPort = ClientError("invalid port")
// SanitizeAnnounce enforces a max and default NumWant and coerces the peer's
// IP address into the proper format.
func SanitizeAnnounce(r *AnnounceRequest, maxNumWant, defaultNumWant uint32) error {
if r.Port == 0 {
return ErrInvalidPort
}
if !r.NumWantProvided {
r.NumWant = defaultNumWant
} else if r.NumWant > maxNumWant {