From 50b0a1694520284f19884d17ed52a03f6ce239bb Mon Sep 17 00:00:00 2001 From: Alin Serdean Date: Thu, 8 Dec 2016 18:44:50 +0000 Subject: [PATCH] datapath-windows: Conntrack move null checks to functions Add null checks inside OvsConntrackValidateIcmpPacket, OvsConntrackValidateTcpPacket to make the functions self-contained. Signed-off-by: Alin Gabriel Serdean Suggested-by: Yin Lin Acked-by: Sairam Venugopal Signed-off-by: Gurucharan Shetty --- datapath-windows/ovsext/Conntrack-icmp.c | 4 ++++ datapath-windows/ovsext/Conntrack-tcp.c | 6 +++++- datapath-windows/ovsext/Conntrack.c | 4 ++-- 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/datapath-windows/ovsext/Conntrack-icmp.c b/datapath-windows/ovsext/Conntrack-icmp.c index 7db8e7d0ed8..b1b604377aa 100644 --- a/datapath-windows/ovsext/Conntrack-icmp.c +++ b/datapath-windows/ovsext/Conntrack-icmp.c @@ -59,6 +59,10 @@ OvsConntrackUpdateIcmpEntry(OVS_CT_ENTRY* conn_, BOOLEAN OvsConntrackValidateIcmpPacket(const ICMPHdr *icmp) { + if (!icmp) { + return FALSE; + } + return icmp->type == ICMP4_ECHO_REQUEST || icmp->type == ICMP4_INFO_REQUEST || icmp->type == ICMP4_TIMESTAMP_REQUEST; diff --git a/datapath-windows/ovsext/Conntrack-tcp.c b/datapath-windows/ovsext/Conntrack-tcp.c index c7fcfa8fff7..1c46bb015d5 100644 --- a/datapath-windows/ovsext/Conntrack-tcp.c +++ b/datapath-windows/ovsext/Conntrack-tcp.c @@ -457,9 +457,13 @@ OvsConntrackUpdateTcpEntry(OVS_CT_ENTRY* conn_, BOOLEAN OvsConntrackValidateTcpPacket(const TCPHdr *tcp) { + if (!tcp) { + return FALSE; + } + UINT16 tcp_flags = ntohs(tcp->flags); - if (tcp == NULL || OvsCtInvalidTcpFlags(tcp_flags)) { + if (OvsCtInvalidTcpFlags(tcp_flags)) { return FALSE; } diff --git a/datapath-windows/ovsext/Conntrack.c b/datapath-windows/ovsext/Conntrack.c index 84c409194e7..47dba9dc8cf 100644 --- a/datapath-windows/ovsext/Conntrack.c +++ b/datapath-windows/ovsext/Conntrack.c @@ -199,7 +199,7 @@ OvsCtEntryCreate(PNET_BUFFER_LIST curNbl, TCPHdr tcpStorage; const TCPHdr *tcp; tcp = OvsGetTcp(curNbl, l4Offset, &tcpStorage); - if (!tcp || !OvsConntrackValidateTcpPacket(tcp)) { + if (!OvsConntrackValidateTcpPacket(tcp)) { goto invalid; } @@ -220,7 +220,7 @@ OvsCtEntryCreate(PNET_BUFFER_LIST curNbl, ICMPHdr storage; const ICMPHdr *icmp; icmp = OvsGetIcmp(curNbl, l4Offset, &storage); - if (!icmp || !OvsConntrackValidateIcmpPacket(icmp)) { + if (!OvsConntrackValidateIcmpPacket(icmp)) { goto invalid; }