Check eventfd read/write returns
authorDavid Woodhouse <dwmw2@infradead.org>
Thu, 8 Jul 2021 19:30:38 +0000 (20:30 +0100)
committerDavid Woodhouse <dwmw2@infradead.org>
Thu, 8 Jul 2021 19:30:38 +0000 (20:30 +0100)
A short write should never happen but we get compiler/Coverity complaints
if we don't check.

Signed-off-by: David Woodhouse <dwmw2@infradead.org>
vhost.c

diff --git a/vhost.c b/vhost.c
index 948276750972d25a7f07b6d3e55faea800847779..6032bc2d6c48e0ea43b577e840f0f5e2e3c90cc0 100644 (file)
--- a/vhost.c
+++ b/vhost.c
@@ -530,7 +530,11 @@ int vhost_tun_mainloop(struct openconnect_info *vpninfo, int *timeout, int reada
 
        if (kick) {
                barrier();
-               write(vpninfo->vhost_kick_fd, &kick, sizeof(kick));
+               if (write(vpninfo->vhost_kick_fd, &kick, sizeof(kick)) != sizeof(kick)) {
+                       /* Can never happen */
+                       vpn_progress(vpninfo, PRG_ERR,
+                                    _("Failed to kick vhost-net eventfd\n"));
+               }
                vpn_progress(vpninfo, PRG_TRACE,
                             _("Kick vhost ring\n"));
                did_work = 1;
@@ -542,7 +546,11 @@ int vhost_tun_mainloop(struct openconnect_info *vpninfo, int *timeout, int reada
         * again. */
        if (!did_work && readable) {
                uint64_t evt;
-               read(vpninfo->vhost_call_fd, &evt, sizeof(evt));
+               if (read(vpninfo->vhost_call_fd, &evt, sizeof(evt)) != sizeof(evt)) {
+                       /* Can never happen */
+                       vpn_progress(vpninfo, PRG_ERR,
+                                    _("Failed to read vhost-net call eventfd\n"));
+               }
        }
 
        /* If we aren't going to have one more turn around the mainloop,