From 6251f74a8d37fa896c8ad78b478ce7ae5f0273ae Mon Sep 17 00:00:00 2001 From: Dirk Engling Date: Tue, 27 Oct 2026 03:20:19 +0100 Subject: Send udp error packet in case of blacklisted torrent --- ot_udp.c | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) (limited to 'ot_udp.c') diff --git a/ot_udp.c b/ot_udp.c index 5bf9d52..4e760bb 100644 --- a/ot_udp.c +++ b/ot_udp.c @@ -105,10 +105,11 @@ int handle_udp6(int64_t serversocket, struct ot_workstruct *ws) { match, return an error packet */ udp_make_connectionid(connid, remoteip, 1); if (inpacket[0] != connid[0] || inpacket[1] != connid[1]) { - const size_t s = sizeof("Connection ID missmatch."); + const char err_idmiss[] = "Connection ID missmatch."; + size_t s = sizeof(err_idmiss); outpacket[0] = htonl(3); outpacket[1] = inpacket[3]; - memcpy(&outpacket[2], "Connection ID missmatch.", s); + memcpy(&outpacket[2], &err_idmiss[0], s); socket_send(serversocket, ws->outbuf, 8 + s, remoteip, remoteport); stats_issue_event(EVENT_CONNID_MISSMATCH, FLAG_UDP, 8 + s); return 1; @@ -173,7 +174,17 @@ int handle_udp6(int64_t serversocket, struct ot_workstruct *ws) { numwant = max_peers; ws->reply = ws->outbuf + 8; - ws->reply_size = 8 + add_peer_to_torrent_and_return_peers(FLAG_UDP, ws, numwant); + ws->reply_size = add_peer_to_torrent_and_return_peers(FLAG_UDP, ws, numwant); + + if (!ws->reply_size) { + const char err_unauth[] = "Requested download is not authorized for use with this tracker."; + size_t s = sizeof(err_unauth); + outpacket[0] = htonl(3); + memcpy(&outpacket[2], &err_unauth[0], s); + socket_send(serversocket, ws->outbuf, 8 + s, remoteip, remoteport); + return 1; + } + ws->reply_size += 8; } socket_send(serversocket, ws->outbuf, ws->reply_size, remoteip, remoteport); -- cgit v1.3