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