From: alex Date: Tue, 12 Apr 2022 00:35:23 +0000 (-0700) Subject: ... X-Git-Url: http://git.infiniteadaptability.org/?a=commitdiff_plain;h=9f7ff6fe84cce877f904cba11614556a74c34263;p=seeder ... --- diff --git a/src/peer/request.c b/src/peer/request.c index b372a5b..9a05731 100644 --- a/src/peer/request.c +++ b/src/peer/request.c @@ -1,12 +1,17 @@ #include static int peer_piece_request_init(struct piece_request**); +static void peer_piece_request_free(struct piece_request*); int peer_request(struct peer *info) { return -1; } -int peer_piece_request_init(struct piece_request **p) { +static void peer_piece_request_free(struct piece_request *p) { + free(p); +} + +static int peer_piece_request_init(struct piece_request **p) { if(NULL==p) { return -1; } (*p) = malloc(sizeof(struct piece_request)); @@ -34,7 +39,12 @@ int peer_request_received(struct peer *info, ssize_t len) { req->begin = BYTES_TO_UINT32_T((&(buf[9]))); req->length = BYTES_TO_UINT32_T((&(buf[13]))); - if(peer_piece_queue(info,req)<0) { return -1; } + if(req->length>16384) { goto clean; } + + if(peer_piece_queue(info,req)<0) { goto clean; } return 1; +clean: + peer_piece_request_free(req); + return -1; }