From: Guus Sliepen Date: Mon, 8 Dec 2014 15:18:30 +0000 (+0100) Subject: Prevent FIN bit from being sent too early. X-Git-Url: http://git.meshlink.io/?p=utcp;a=commitdiff_plain;h=387d0814ba7ede1246e00f95912c5256c8d59e08 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. --- 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: