From 9f7ff6fe84cce877f904cba11614556a74c34263 Mon Sep 17 00:00:00 2001 From: alex Date: Mon, 11 Apr 2022 17:35:23 -0700 Subject: [PATCH] ... --- src/peer/request.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) 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; } -- 2.30.2