From cb4848e35951d8dc232643b45116fb54655ffa30 Mon Sep 17 00:00:00 2001 From: Martin Schwenke Date: Fri, 17 Aug 2018 14:14:12 +1000 Subject: [PATCH] ctdb-common: Fix error handling when parsing TCP packets Signed-off-by: Martin Schwenke Reviewed-by: Amitay Isaacs --- ctdb/common/system_socket.c | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/ctdb/common/system_socket.c b/ctdb/common/system_socket.c index c72c61ad978..a52a7947af8 100644 --- a/ctdb/common/system_socket.c +++ b/ctdb/common/system_socket.c @@ -799,7 +799,7 @@ int ctdb_sys_read_tcp_packet(int s, void *private_data, ret = recv(s, pkt, RCVPKTSIZE, MSG_TRUNC); if (ret < sizeof(*eth)+sizeof(*ip)) { - return -1; + return EMSGSIZE; } ZERO_STRUCTP(src); @@ -815,21 +815,21 @@ int ctdb_sys_read_tcp_packet(int s, void *private_data, /* We only want IPv4 packets */ if (ip->version != 4) { - return -1; + return ENOMSG; } /* Dont look at fragments */ if ((ntohs(ip->frag_off)&0x1fff) != 0) { - return -1; + return ENOMSG; } /* we only want TCP */ if (ip->protocol != IPPROTO_TCP) { - return -1; + return ENOMSG; } /* make sure its not a short packet */ if (offsetof(struct tcphdr, th_ack) + 4 + (ip->ihl*4) + sizeof(*eth) > ret) { - return -1; + return EMSGSIZE; } /* TCP */ tcp = (struct tcphdr *)((ip->ihl*4) + (char *)ip); @@ -857,7 +857,7 @@ int ctdb_sys_read_tcp_packet(int s, void *private_data, /* we only want TCP */ if (ip6->ip6_nxt != IPPROTO_TCP) { - return -1; + return ENOMSG; } /* TCP */ @@ -884,7 +884,7 @@ int ctdb_sys_read_tcp_packet(int s, void *private_data, return 0; } - return -1; + return ENOMSG; } #else /* HAVE_AF_PACKET */ @@ -933,7 +933,7 @@ int ctdb_sys_read_tcp_packet(int s, buffer=pcap_next(pt, &pkthdr); if (buffer==NULL) { - return -1; + return ENOMSG; } ZERO_STRUCTP(src); @@ -949,21 +949,21 @@ int ctdb_sys_read_tcp_packet(int s, /* We only want IPv4 packets */ if (ip->ip_v != 4) { - return -1; + return ENOMSG; } /* Dont look at fragments */ if ((ntohs(ip->ip_off)&0x1fff) != 0) { - return -1; + return ENOMSG; } /* we only want TCP */ if (ip->ip_p != IPPROTO_TCP) { - return -1; + return ENOMSG; } /* make sure its not a short packet */ if (offsetof(struct tcphdr, th_ack) + 4 + (ip->ip_hl*4) + sizeof(*eth) > pkthdr.caplen) { - return -1; + return EMSGSIZE; } /* TCP */ tcp = (struct tcphdr *)((ip->ip_hl*4) + (char *)ip); @@ -991,7 +991,7 @@ int ctdb_sys_read_tcp_packet(int s, /* we only want TCP */ if (ip6->ip6_nxt != IPPROTO_TCP) { - return -1; + return ENOMSG; } /* TCP */ @@ -1018,7 +1018,7 @@ int ctdb_sys_read_tcp_packet(int s, return 0; } - return -1; + return ENOMSG; } #endif /* HAVE_AF_PACKET */ -- 2.47.2