From 502e89f4ad7ede50634c74577859732e5b8d0428 Mon Sep 17 00:00:00 2001 From: goldsimon Date: Fri, 16 Oct 2009 21:07:48 +0000 Subject: [PATCH] Fixed bug #27315: zero window probe and FIN --- CHANGELOG | 3 +++ src/core/tcp_out.c | 17 +++++++++++++---- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 7afb3268..4c99bfcd 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -43,6 +43,9 @@ HISTORY ++ Bugfixes: + 2009-10-16: Simon Goldschmidt + * tcp_out.c: Fixed bug #27315: zero window probe and FIN + 2009-10-16: Simon Goldschmidt * ip.c: Fixed bug #27390: Source IP check in ip_input() causes it to drop valid DHCP packets -> allow 0.0.0.0 as source address when LWIP_DHCP is diff --git a/src/core/tcp_out.c b/src/core/tcp_out.c index bef38b26..60d0f87b 100644 --- a/src/core/tcp_out.c +++ b/src/core/tcp_out.c @@ -926,6 +926,8 @@ tcp_zero_window_probe(struct tcp_pcb *pcb) struct pbuf *p; struct tcp_hdr *tcphdr; struct tcp_seg *seg; + u16_t len; + u8_t is_fin; LWIP_DEBUGF(TCP_DEBUG, ("tcp_zero_window_probe: sending ZERO WINDOW probe to %" @@ -946,8 +948,10 @@ tcp_zero_window_probe(struct tcp_pcb *pcb) if(seg == NULL) return; - p = pbuf_alloc(PBUF_IP, TCP_HLEN + 1, PBUF_RAM); - + is_fin = (TCPH_FLAGS(seg->tcphdr) & TCP_FIN) != 0; + len = is_fin ? TCP_HLEN : TCP_HLEN + 1; + + p = pbuf_alloc(PBUF_IP, len, PBUF_RAM); if(p == NULL) { LWIP_DEBUGF(TCP_DEBUG, ("tcp_zero_window_probe: no memory for pbuf\n")); return; @@ -957,8 +961,13 @@ tcp_zero_window_probe(struct tcp_pcb *pcb) tcphdr = tcp_output_set_header(pcb, p, 0, seg->tcphdr->seqno); - /* Copy in one byte from the head of the unacked queue */ - *((char *)p->payload + sizeof(struct tcp_hdr)) = *(char *)seg->dataptr; + if (is_fin) { + /* FIN segment, no data */ + TCPH_FLAGS_SET(tcphdr, TCP_ACK | TCP_FIN); + } else { + /* Data segment, copy in one byte from the head of the unacked queue */ + *((char *)p->payload + sizeof(struct tcp_hdr)) = *(char *)seg->dataptr; + } #if CHECKSUM_GEN_TCP tcphdr->chksum = inet_chksum_pseudo(p, &pcb->local_ip, &pcb->remote_ip,