mirror of
https://github.com/LBRYFoundation/tracker.git
synced 2025-08-23 17:47:29 +00:00
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.
|
// ErrInvalidIP indicates an invalid IP for an Announce.
|
||||||
var ErrInvalidIP = ClientError("invalid IP")
|
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
|
// SanitizeAnnounce enforces a max and default NumWant and coerces the peer's
|
||||||
// IP address into the proper format.
|
// IP address into the proper format.
|
||||||
func SanitizeAnnounce(r *AnnounceRequest, maxNumWant, defaultNumWant uint32) error {
|
func SanitizeAnnounce(r *AnnounceRequest, maxNumWant, defaultNumWant uint32) error {
|
||||||
|
if r.Port == 0 {
|
||||||
|
return ErrInvalidPort
|
||||||
|
}
|
||||||
|
|
||||||
if !r.NumWantProvided {
|
if !r.NumWantProvided {
|
||||||
r.NumWant = defaultNumWant
|
r.NumWant = defaultNumWant
|
||||||
} else if r.NumWant > maxNumWant {
|
} else if r.NumWant > maxNumWant {
|
||||||
|
|
Loading…
Add table
Reference in a new issue