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