From aa0c5f6a3ce7a611413b0b61e0cc4044ccb5cc84 Mon Sep 17 00:00:00 2001 From: Tao Wu Date: Wed, 8 Nov 2017 14:53:40 -0800 Subject: slirp: don't zero the whole ti_i when m == NULL 98c63057d2144fb81681580cd84c13c93794c96e ('slirp: Factorizing tcpiphdr structure with an union') introduced a memset call to clear possibly-undefined fields in ti. This however overwrites src/dst/pr which are used below. So let us clear only the unused fields. This should fix some rare cases (some RST cases, keep alive probes) where packets would be sent to 0.0.0.0. Signed-off-by: Tao Wu Signed-off-by: Samuel Thibault --- tcp_subr.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/tcp_subr.c b/tcp_subr.c index 59f61fc..d72597c 100644 --- a/tcp_subr.c +++ b/tcp_subr.c @@ -145,7 +145,16 @@ void tcp_respond(struct tcpcb *tp, struct tcpiphdr *ti, struct mbuf *m, m->m_data += IF_MAXLINKHDR; *mtod(m, struct tcpiphdr *) = *ti; ti = mtod(m, struct tcpiphdr *); - memset(&ti->ti, 0, sizeof(ti->ti)); + switch (af) { + case AF_INET: + ti->ti.ti_i4.ih_x1 = 0; + break; + case AF_INET6: + ti->ti.ti_i6.ih_x1 = 0; + break; + default: + g_assert_not_reached(); + } flags = TH_ACK; } else { /* -- cgit v1.1