diff options
author | Martin Schwenke <martin@meltin.net> | 2018-08-17 14:14:12 +1000 |
---|---|---|
committer | Amitay Isaacs <amitay@samba.org> | 2018-08-30 04:48:58 +0200 |
commit | cb4848e35951d8dc232643b45116fb54655ffa30 (patch) | |
tree | 7237bd2b2d74b8d456e027c34ee32984362ac968 /ctdb/common | |
parent | f3a1f1e1fa9a8a0fe6ffd3809a64d8185cb561b7 (diff) | |
download | samba-cb4848e35951d8dc232643b45116fb54655ffa30.tar.gz |
ctdb-common: Fix error handling when parsing TCP packets
Signed-off-by: Martin Schwenke <martin@meltin.net>
Reviewed-by: Amitay Isaacs <amitay@gmail.com>
Diffstat (limited to 'ctdb/common')
-rw-r--r-- | ctdb/common/system_socket.c | 28 |
1 files 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 */ |