bittorrent: validate port != 0 for announces
This commit is contained in:
parent
a8bc51ba1d
commit
b19f7115df
1 changed files with 7 additions and 0 deletions
|
@ -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 {
|
||||
|
|
Loading…
Add table
Reference in a new issue