aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Levon <john.levon@nutanix.com>2021-04-06 13:42:51 +0100
committerGitHub <noreply@github.com>2021-04-06 13:42:51 +0100
commite97a5e8c911acd8826542b1de30fb834901f4e76 (patch)
tree5c57c41dcc1f8c8b50ec8b88b8aee97a88efff44
parentb2ce987ce3954a23a806e875a65304989fae7067 (diff)
downloadlibvfio-user-e97a5e8c911acd8826542b1de30fb834901f4e76.zip
libvfio-user-e97a5e8c911acd8826542b1de30fb834901f4e76.tar.gz
libvfio-user-e97a5e8c911acd8826542b1de30fb834901f4e76.tar.bz2
tran_sock: fix EOF handling (#414)
Consistently check for EOF, returning ENOMSG as an error to consumers. Signed-off-by: John Levon <john.levon@nutanix.com> Reviewed-by: Thanos Makatos <thanos.makatos@nutanix.com>
-rw-r--r--lib/tran_sock.c26
1 files changed, 16 insertions, 10 deletions
diff --git a/lib/tran_sock.c b/lib/tran_sock.c
index a0fe931..9a58570 100644
--- a/lib/tran_sock.c
+++ b/lib/tran_sock.c
@@ -171,6 +171,8 @@ get_msg(void *data, size_t len, int *fds, size_t *nr_fds, int sock_fd,
ret = recvmsg(sock_fd, &msg, sock_flags);
if (ret == -1) {
return -errno;
+ } else if (ret == 0) {
+ return -ENOMSG;
}
if (msg.msg_flags & MSG_CTRUNC || msg.msg_flags & MSG_TRUNC) {
@@ -252,9 +254,10 @@ tran_sock_recv_fds(int sock, struct vfio_user_header *hdr, bool is_reply,
ret = recv(sock, data, MIN(hdr->msg_size - sizeof(*hdr), *len),
MSG_WAITALL);
if (ret < 0) {
- return ret;
- }
- if (*len != (size_t)ret) { /* FIXME we should allow receiving less */
+ return -errno;
+ } else if (ret == 0) {
+ return -ENOMSG;
+ } else if (*len != (size_t)ret) { /* FIXME we should allow receiving less */
return -EINVAL;
}
*len = ret;
@@ -307,11 +310,13 @@ tran_sock_recv_alloc(int sock, struct vfio_user_header *hdr, bool is_reply,
ret = recv(sock, data, len, MSG_WAITALL);
if (ret < 0) {
+ ret = -errno;
free(data);
- return -errno;
- }
-
- if (len != (size_t)ret) {
+ return ret;
+ } else if (ret == 0) {
+ free(data);
+ return -ENOMSG;
+ } else if (len != (size_t)ret) {
free(data);
return -EINVAL;
}
@@ -806,9 +811,10 @@ tran_sock_recv_body(vfu_ctx_t *vfu_ctx, const struct vfio_user_header *hdr,
ret = -errno;
free(data);
return ret;
- }
-
- if (ret != (int)body_size) {
+ } else if (ret == 0) {
+ free(data);
+ return -ENOMSG;
+ } else if (ret != (int)body_size) {
vfu_log(vfu_ctx, LOG_ERR, "msg%#hx: short read: expected=%d, actual=%d",
hdr->msg_id, body_size, ret);
free(data);