From 6bf09ecbe8203d0f8c020e6b0b55202e91e216c9 Mon Sep 17 00:00:00 2001 From: Pranith Kumar K Date: Sat, 7 Sep 2019 20:18:01 +0530 Subject: cluster/ec: Fix coverity issues Fixed the following coverity issue in both flush/fsync >>> CID 1404964: Null pointer dereferences (REVERSE_INULL) >>> Null-checking "fd" suggests that it may be null, but it has already been dereferenced on all paths leading to the check. >>> if (fd != NULL) { >>> fop->fd = fd_ref(fd); >>> if (fop->fd == NULL) { >>> gf_msg(this->name, GF_LOG_ERROR, 0, >>> "Failed to reference a " >>> "file descriptor."); fixes bz#1748836 Change-Id: I19c05d585e23f8fbfbc195d1f3775ec528eed671 Signed-off-by: Pranith Kumar K --- xlators/cluster/ec/src/ec-generic.c | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/xlators/cluster/ec/src/ec-generic.c b/xlators/cluster/ec/src/ec-generic.c index 4cd47a83b84..884deb93669 100644 --- a/xlators/cluster/ec/src/ec-generic.c +++ b/xlators/cluster/ec/src/ec-generic.c @@ -193,12 +193,14 @@ ec_flush(call_frame_t *frame, xlator_t *this, uintptr_t target, GF_VALIDATE_OR_GOTO(this->name, frame, out); GF_VALIDATE_OR_GOTO(this->name, this->private, out); - error = ec_validate_fd(fd, this); - if (error) { - gf_msg(this->name, GF_LOG_ERROR, EBADF, EC_MSG_FD_BAD, - "Failing %s on %s", gf_fop_list[GF_FOP_FLUSH], - fd->inode ? uuid_utoa(fd->inode->gfid) : ""); - goto out; + if (fd) { + error = ec_validate_fd(fd, this); + if (error) { + gf_msg(this->name, GF_LOG_ERROR, EBADF, EC_MSG_FD_BAD, + "Failing %s on %s", gf_fop_list[GF_FOP_FLUSH], + fd->inode ? uuid_utoa(fd->inode->gfid) : ""); + goto out; + } } fop = ec_fop_data_allocate(frame, this, GF_FOP_FLUSH, 0, target, fop_flags, @@ -417,12 +419,14 @@ ec_fsync(call_frame_t *frame, xlator_t *this, uintptr_t target, GF_VALIDATE_OR_GOTO(this->name, frame, out); GF_VALIDATE_OR_GOTO(this->name, this->private, out); - error = ec_validate_fd(fd, this); - if (error) { - gf_msg(this->name, GF_LOG_ERROR, EBADF, EC_MSG_FD_BAD, - "Failing %s on %s", gf_fop_list[GF_FOP_FSYNC], - fd->inode ? uuid_utoa(fd->inode->gfid) : ""); - goto out; + if (fd) { + error = ec_validate_fd(fd, this); + if (error) { + gf_msg(this->name, GF_LOG_ERROR, EBADF, EC_MSG_FD_BAD, + "Failing %s on %s", gf_fop_list[GF_FOP_FSYNC], + fd->inode ? uuid_utoa(fd->inode->gfid) : ""); + goto out; + } } fop = ec_fop_data_allocate(frame, this, GF_FOP_FSYNC, 0, target, fop_flags, -- cgit