Skip to content

Commit b91c5e4

Browse files
committed
Fixing a nasty peer_id bug
1 parent 16f9d8a commit b91c5e4

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

src/torrust_http_tracker/errors.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ pub enum ServerError {
99
#[error("info_hash is either missing or invalid")]
1010
InvalidInfoHash,
1111

12+
#[error("peer_id is either missing or invalid")]
13+
InvalidPeerId,
14+
1215
#[error("could not find remote address")]
1316
AddressNotFound,
1417

src/torrust_http_tracker/handlers.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,10 @@ pub async fn handle_announce(announce_request: AnnounceRequest, auth_key: Option
4545
false => announce_request.peer_addr.ip()
4646
};
4747

48+
if announce_request.peer_id.len() != 40 {
49+
return Err(reject::custom(ServerError::InvalidPeerId))
50+
}
51+
4852
let peer = TorrentPeer::from_http_announce_request(&announce_request, peer_ip, tracker.config.get_ext_ip());
4953
let torrent_stats = tracker.update_torrent_with_peer_and_get_stats(&announce_request.info_hash, &peer).await;
5054
// get all peers excluding the client_addr

0 commit comments

Comments
 (0)