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