e3c68b
From ccf7775760dd923e21341438725946737eb8d8af Mon Sep 17 00:00:00 2001
e3c68b
From: Pranith Kumar K <pkarampu@redhat.com>
e3c68b
Date: Sat, 7 Sep 2019 20:18:01 +0530
e3c68b
Subject: [PATCH 288/297] cluster/ec: Fix coverity issues
e3c68b
e3c68b
Fixed the following coverity issue in both flush/fsync
e3c68b
>>>     CID 1404964:  Null pointer dereferences  (REVERSE_INULL)
e3c68b
>>>     Null-checking "fd" suggests that it may be null, but it has already
e3c68b
been dereferenced on all paths leading to the check.
e3c68b
>>>         if (fd != NULL) {
e3c68b
>>>           fop->fd = fd_ref(fd);
e3c68b
>>>             if (fop->fd == NULL) {
e3c68b
>>>                 gf_msg(this->name, GF_LOG_ERROR, 0,
e3c68b
>>>                        "Failed to reference a "
e3c68b
>>>                        "file descriptor.");
e3c68b
e3c68b
Upstream-patch: https://review.gluster.org/c/glusterfs/+/23382
e3c68b
fixes: bz#1745107
e3c68b
Change-Id: I19c05d585e23f8fbfbc195d1f3775ec528eed671
e3c68b
Signed-off-by: Pranith Kumar K <pkarampu@redhat.com>
e3c68b
Reviewed-on: https://code.engineering.redhat.com/gerrit/180673
e3c68b
Tested-by: RHGS Build Bot <nigelb@redhat.com>
e3c68b
Reviewed-by: Ashish Pandey <aspandey@redhat.com>
e3c68b
Reviewed-by: Sunil Kumar Heggodu Gopala Acharya <sheggodu@redhat.com>
e3c68b
---
e3c68b
 xlators/cluster/ec/src/ec-generic.c | 28 ++++++++++++++++------------
e3c68b
 1 file changed, 16 insertions(+), 12 deletions(-)
e3c68b
e3c68b
diff --git a/xlators/cluster/ec/src/ec-generic.c b/xlators/cluster/ec/src/ec-generic.c
e3c68b
index b019050..192bb02 100644
e3c68b
--- a/xlators/cluster/ec/src/ec-generic.c
e3c68b
+++ b/xlators/cluster/ec/src/ec-generic.c
e3c68b
@@ -196,12 +196,14 @@ ec_flush(call_frame_t *frame, xlator_t *this, uintptr_t target,
e3c68b
     GF_VALIDATE_OR_GOTO(this->name, frame, out);
e3c68b
     GF_VALIDATE_OR_GOTO(this->name, this->private, out);
e3c68b
 
e3c68b
-    error = ec_validate_fd(fd, this);
e3c68b
-    if (error) {
e3c68b
-        gf_msg(this->name, GF_LOG_ERROR, EBADF, EC_MSG_FD_BAD,
e3c68b
-               "Failing %s on %s", gf_fop_list[GF_FOP_FLUSH],
e3c68b
-               fd->inode ? uuid_utoa(fd->inode->gfid) : "");
e3c68b
-        goto out;
e3c68b
+    if (fd) {
e3c68b
+        error = ec_validate_fd(fd, this);
e3c68b
+        if (error) {
e3c68b
+            gf_msg(this->name, GF_LOG_ERROR, EBADF, EC_MSG_FD_BAD,
e3c68b
+                   "Failing %s on %s", gf_fop_list[GF_FOP_FLUSH],
e3c68b
+                   fd->inode ? uuid_utoa(fd->inode->gfid) : "");
e3c68b
+            goto out;
e3c68b
+        }
e3c68b
     }
e3c68b
 
e3c68b
     fop = ec_fop_data_allocate(frame, this, GF_FOP_FLUSH, 0, target, fop_flags,
e3c68b
@@ -420,12 +422,14 @@ ec_fsync(call_frame_t *frame, xlator_t *this, uintptr_t target,
e3c68b
     GF_VALIDATE_OR_GOTO(this->name, frame, out);
e3c68b
     GF_VALIDATE_OR_GOTO(this->name, this->private, out);
e3c68b
 
e3c68b
-    error = ec_validate_fd(fd, this);
e3c68b
-    if (error) {
e3c68b
-        gf_msg(this->name, GF_LOG_ERROR, EBADF, EC_MSG_FD_BAD,
e3c68b
-               "Failing %s on %s", gf_fop_list[GF_FOP_FSYNC],
e3c68b
-               fd->inode ? uuid_utoa(fd->inode->gfid) : "");
e3c68b
-        goto out;
e3c68b
+    if (fd) {
e3c68b
+        error = ec_validate_fd(fd, this);
e3c68b
+        if (error) {
e3c68b
+            gf_msg(this->name, GF_LOG_ERROR, EBADF, EC_MSG_FD_BAD,
e3c68b
+                   "Failing %s on %s", gf_fop_list[GF_FOP_FSYNC],
e3c68b
+                   fd->inode ? uuid_utoa(fd->inode->gfid) : "");
e3c68b
+            goto out;
e3c68b
+        }
e3c68b
     }
e3c68b
 
e3c68b
     fop = ec_fop_data_allocate(frame, this, GF_FOP_FSYNC, 0, target, fop_flags,
e3c68b
-- 
e3c68b
1.8.3.1
e3c68b