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