mirror of
https://github.com/sot-tech/mochi.git
synced 2026-05-20 06:44:48 -07:00
bittorrent: validate port != 0 for announces
This commit is contained in:
@@ -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 {
|
||||||
|
|||||||
Reference in New Issue
Block a user