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