From b19f7115dffcbe7fa64d1264b5f34294f00b2613 Mon Sep 17 00:00:00 2001 From: Leo Balduf Date: Tue, 13 Feb 2018 10:13:57 +0100 Subject: [PATCH] bittorrent: validate port != 0 for announces --- bittorrent/sanitize.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/bittorrent/sanitize.go b/bittorrent/sanitize.go index 9cc7402..4d80ca7 100644 --- a/bittorrent/sanitize.go +++ b/bittorrent/sanitize.go @@ -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 {