]> infiniteadaptability.org Git - seeder/commitdiff
...
authoralex <[email protected]>
Tue, 12 Apr 2022 00:35:23 +0000 (17:35 -0700)
committeralex <[email protected]>
Tue, 12 Apr 2022 00:35:23 +0000 (17:35 -0700)
src/peer/request.c

index b372a5bb29ec0b7af0c3e709d8af0fb0d71c5f92..9a05731c1a37bc2e698e35a5bd9545b4a201b02f 100644 (file)
@@ -1,12 +1,17 @@
 #include<peer.h>
 
 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;
 }