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