From 387d0814ba7ede1246e00f95912c5256c8d59e08 Mon Sep 17 00:00:00 2001 From: Guus Sliepen Date: Mon, 8 Dec 2014 16:18:30 +0100 Subject: [PATCH] Prevent FIN bit from being sent too early. Due to a logic bug in ack(), the FIN bit could be set on a too early packet, if utcp_shutdown() was called with a full send buffer. --- utcp.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/utcp.c b/utcp.c index 186b63e..1d8f4b2 100644 --- a/utcp.c +++ b/utcp.c @@ -366,7 +366,7 @@ static void ack(struct utcp_connection *c, bool sendatleastone) { c->snd.nxt += seglen; left -= seglen; - if(c->state != ESTABLISHED && !left && seglen) { + if(c->state != ESTABLISHED && seglen && c->snd.nxt == c->snd.last) { switch(c->state) { case FIN_WAIT_1: case CLOSING: @@ -954,7 +954,7 @@ reset: } int utcp_shutdown(struct utcp_connection *c, int dir) { - debug("%p shutdown %d\n", c ? c->utcp : NULL, dir); + debug("%p shutdown %d at %u\n", c ? c->utcp : NULL, dir, c->snd.last); if(!c) { errno = EFAULT; return -1; @@ -967,6 +967,7 @@ int utcp_shutdown(struct utcp_connection *c, int dir) { } // TODO: handle dir + // TODO: check that repeated calls with the same parameters should have no effect switch(c->state) { case CLOSED: -- 2.39.5