05bba0
From 25730930b496dd639afe8906744ce9ebeb7db7e9 Mon Sep 17 00:00:00 2001
05bba0
From: Jeffrey Cody <jcody@redhat.com>
05bba0
Date: Wed, 5 Aug 2015 14:38:26 +0200
05bba0
Subject: [PATCH 3/3] block: coverity fix: check return value for fcntl in
05bba0
 gluster
05bba0
05bba0
Message-id: <9a482772dc4e110d2a774bbed0e1dbecdaaec43e.1438784597.git.jcody@redhat.com>
05bba0
Patchwork-id: 67323
05bba0
O-Subject: [RHEL-7.2 qemu-kvm PATCH v3] block: coverity fix: check return value for fcntl in gluster
05bba0
Bugzilla: 1219217
05bba0
RH-Acked-by: Max Reitz <mreitz@redhat.com>
05bba0
RH-Acked-by: Fam Zheng <famz@redhat.com>
05bba0
RH-Acked-by: Stefan Hajnoczi <stefanha@redhat.com>
05bba0
05bba0
Check return value in the Gluster driver for fcntl, as pointed
05bba0
out by coverity.
05bba0
05bba0
Cleanup of s->fds is done inline in the error handling for the fcntl()
05bba0
call, rather than in the function cleanup, to keep changes minimal for
05bba0
future backports.
05bba0
05bba0
Downstream-only, as upstream Gluster driver does not use fcntl anymore.
05bba0
05bba0
Signed-off-by: Jeff Cody <jcody@redhat.com>
05bba0
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
05bba0
---
05bba0
 block/gluster.c | 8 +++++++-
05bba0
 1 file changed, 7 insertions(+), 1 deletion(-)
05bba0
05bba0
diff --git a/block/gluster.c b/block/gluster.c
05bba0
index 5f85799..1793386 100644
05bba0
--- a/block/gluster.c
05bba0
+++ b/block/gluster.c
05bba0
@@ -357,7 +357,13 @@ static int qemu_gluster_open(BlockDriverState *bs,  QDict *options,
05bba0
         ret = -errno;
05bba0
         goto out;
05bba0
     }
05bba0
-    fcntl(s->fds[GLUSTER_FD_READ], F_SETFL, O_NONBLOCK);
05bba0
+    ret = fcntl(s->fds[GLUSTER_FD_READ], F_SETFL, O_NONBLOCK);
05bba0
+    if (ret < 0) {
05bba0
+        ret = -errno;
05bba0
+        close(s->fds[GLUSTER_FD_READ]);
05bba0
+        close(s->fds[GLUSTER_FD_WRITE]);
05bba0
+        goto out;
05bba0
+    }
05bba0
     qemu_aio_set_fd_handler(s->fds[GLUSTER_FD_READ],
05bba0
         qemu_gluster_aio_event_reader, NULL, qemu_gluster_aio_flush_cb, s);
05bba0
 
05bba0
-- 
05bba0
1.8.3.1
05bba0