diff options
author | Martin Schwenke <martin@meltin.net> | 2019-06-24 16:36:47 +1000 |
---|---|---|
committer | Amitay Isaacs <amitay@samba.org> | 2019-07-05 05:03:24 +0000 |
commit | 271d96e4fcae7228e460cba558041f4656588f22 (patch) | |
tree | 721a2eb79bdd493711c49c21af0d71a8ea2089fe /ctdb/common | |
parent | 0ab5d5cece2b7d22cabfffd090cf3c675dca4af5 (diff) | |
download | samba-271d96e4fcae7228e460cba558041f4656588f22.tar.gz |
ctdb-common: Fix error handling
According to the documentation, sendto() should either send the packet
as given or return with an error. However, given that it can return
the number of bytes sent, treat the theoretical error of a short
packet send separately, since errno would not be set in this case.
Similarly, treat a short packet recv() separately from an error where
errno is set.
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 | 18 |
1 files changed, 14 insertions, 4 deletions
diff --git a/ctdb/common/system_socket.c b/ctdb/common/system_socket.c index c6800431112..86cbdaab6ad 100644 --- a/ctdb/common/system_socket.c +++ b/ctdb/common/system_socket.c @@ -681,10 +681,14 @@ int ctdb_sys_send_tcp(const ctdb_sock_addr *dest, sizeof(dest->ip)); saved_errno = errno; close(s); - if (ret != len) { + if (ret == -1) { D_ERR("Failed sendto (%s)\n", strerror(saved_errno)); return -1; } + if ((size_t)ret != len) { + DBG_ERR("Failed sendto - didn't send full packet\n"); + return -1; + } break; case AF_INET6: @@ -722,11 +726,14 @@ int ctdb_sys_send_tcp(const ctdb_sock_addr *dest, sizeof(tmpdest)); saved_errno = errno; close(s); - - if (ret != len) { + if (ret == -1) { D_ERR("Failed sendto (%s)\n", strerror(saved_errno)); return -1; } + if ((size_t)ret != len) { + DBG_ERR("Failed sendto - didn't send full packet\n"); + return -1; + } break; default: @@ -914,7 +921,10 @@ int ctdb_sys_read_tcp_packet(int s, void *private_data, int ret; nread = recv(s, pkt, sizeof(pkt), MSG_TRUNC); - if (nread < sizeof(*eth)) { + if (nread == -1) { + return errno; + } + if ((size_t)nread < sizeof(*eth)) { return EMSGSIZE; } |