From a6ea3a99259b6f74c3151d0692d2899b3657b17d Mon Sep 17 00:00:00 2001 From: Guus Sliepen Date: Thu, 16 Apr 2020 02:09:37 +0200 Subject: [PATCH] Fix potential segmentation fault when the receive callback is not set. A few calls to the callback function were missing a check that the callback function pointer was non-NULL. --- utcp.c | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/utcp.c b/utcp.c index aa1c50f..f7c1859 100644 --- a/utcp.c +++ b/utcp.c @@ -1113,11 +1113,14 @@ static void handle_in_order(struct utcp_connection *c, const void *data, size_t size_t offset = len; len = c->sacks[0].offset + c->sacks[0].len; size_t remainder = len - offset; - ssize_t rxd = buffer_call(&c->rcvbuf, c->recv, c, offset, remainder); - if(rxd != (ssize_t)remainder) { - // TODO: handle the application not accepting all data. - abort(); + if(c->recv) { + ssize_t rxd = buffer_call(&c->rcvbuf, c->recv, c, offset, remainder); + + if(rxd != (ssize_t)remainder) { + // TODO: handle the application not accepting all data. + abort(); + } } } } @@ -1132,7 +1135,10 @@ static void handle_in_order(struct utcp_connection *c, const void *data, size_t static void handle_unreliable(struct utcp_connection *c, const struct hdr *hdr, const void *data, size_t len) { // Fast path for unfragmented packets if(!hdr->wnd && !(hdr->ctl & MF)) { - c->recv(c, data, len); + if(c->recv) { + c->recv(c, data, len); + } + c->rcv.nxt = hdr->seq + len; return; } @@ -1159,7 +1165,7 @@ static void handle_unreliable(struct utcp_connection *c, const struct hdr *hdr, } // Send the packet if it's the final fragment - if(!(hdr->ctl & MF)) { + if(!(hdr->ctl & MF) && c->recv) { buffer_call(&c->rcvbuf, c->recv, c, 0, hdr->wnd + len); } -- 2.39.2