From: Guus Sliepen Date: Sat, 11 Apr 2020 22:29:49 +0000 (+0200) Subject: Handle incoming packets that don't fit into the receive buffer. X-Git-Url: https://git.meshlink.io/?a=commitdiff_plain;h=9809749c054e9beb9b01aa4e7e2f597871da133c;p=utcp Handle incoming packets that don't fit into the receive buffer. If the receive buffer size is reduced while there are still incoming packets in flight, it can be that those will not fit inside the receive buffer. Instead of calling abort(), just handle as much of the packet as we can fit in the receive buffer, or handle the whole packet if it is in order since we bypass the receive buffer in that case. --- diff --git a/utcp.c b/utcp.c index fd507f9..75d4f83 100644 --- a/utcp.c +++ b/utcp.c @@ -1046,8 +1046,14 @@ static void handle_out_of_order(struct utcp_connection *c, uint32_t offset, cons // Packet loss or reordering occured. Store the data in the buffer. ssize_t rxd = buffer_put_at(&c->rcvbuf, offset, data, len); - if(rxd < 0 || (size_t)rxd < len) { - abort(); + if(rxd <= 0) { + debug(c, "packet outside receive buffer, dropping\n"); + return; + } + + if((size_t)rxd < len) { + debug(c, "packet partially outside receive buffer\n"); + len = rxd; } // Make note of where we put it. @@ -1169,10 +1175,6 @@ static void handle_incoming_data(struct utcp_connection *c, const struct hdr *hd uint32_t offset = seqdiff(hdr->seq, c->rcv.nxt); - if(offset + len > c->rcvbuf.maxsize) { - abort(); - } - if(offset) { handle_out_of_order(c, offset, data, len); } else {