From c2d3703ed70d13063d693f135d89538db526ad5c Mon Sep 17 00:00:00 2001 From: Atin Mukherjee Date: Tue, 28 Jun 2016 15:32:17 +0530 Subject: glusterd/cli: coverity fixes A downstream coverity run has revealed few of the following coverity defects. Since the downstream code is a clone of a specific upstream branch the defects hold true for the upstream as well. Defect type: NEGATIVE_RETURNS xlators/mgmt/glusterd/src/glusterd-rpc-ops.c:641: negative_returns: "op_errno" is passed to a parameter that cannot be negative. Defect type: BUFFER_SIZE_WARNING xlators/mgmt/glusterd/src/glusterd-volume-ops.c:2124: buffer_size_warning: Calling strncpy with a maximum size argument of 261 bytes on destination array "volinfo->volname" of size 261 bytes might leave the destination string unterminated. Defect type: BUFFER_SIZE_WARNING xlators/mgmt/glusterd/src/glusterd-volgen.c:4888: buffer_size_warning: Calling strncpy with a maximum size argument of 261 bytes on destination array "volinfo->volname" of size 261 bytes might leave the destination string unterminated. Defect type: STRING_OVERFLOW xlators/mgmt/glusterd/src/glusterd-volgen.c:3449: string_overflow: You might overrun the 256 byte destination string "tmp_volname" by writing 261 bytes from "volinfo->volname". Defect type: BUFFER_SIZE_WARNING xlators/mgmt/glusterd/src/glusterd-utils.c:3392: buffer_size_warning: Calling strncpy with a maximum size argument of 261 bytes on destination array "new_volinfo->volname" of size 261 bytes might leave the destination string unterminated. Defect type: NO_EFFECT xlators/mgmt/glusterd/src/glusterd-utils.c:7359: remediation: Was "rebal->rebalance_id" formerly declared as a pointer? Defect type: USE_AFTER_FREE xlators/mgmt/glusterd/src/glusterd-utils.c:7115: pass_freed_arg: Passing freed pointer "volinfo" as an argument to "glusterd_friend_contains_vol_bricks". Defect type: DEADCODE cli/src/cli-cmd-parser.c:1767: dead_error_begin: Execution cannot reach this statement: "ret = -1;". Change-Id: Ie941bdf31923e2f39618dd94bfae16fdb3ad65f1 BUG: 789278 Signed-off-by: Atin Mukherjee Reviewed-on: http://review.gluster.org/14818 Smoke: Gluster Build System NetBSD-regression: NetBSD Build System CentOS-regression: Gluster Build System Reviewed-by: Jeff Darcy --- xlators/mgmt/glusterd/src/glusterd-utils.c | 31 +++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-) (limited to 'xlators/mgmt/glusterd/src/glusterd-utils.c') diff --git a/xlators/mgmt/glusterd/src/glusterd-utils.c b/xlators/mgmt/glusterd/src/glusterd-utils.c index 19173a4d015..73014651d3b 100644 --- a/xlators/mgmt/glusterd/src/glusterd-utils.c +++ b/xlators/mgmt/glusterd/src/glusterd-utils.c @@ -3455,7 +3455,7 @@ glusterd_import_volinfo (dict_t *peer_data, int count, ret = glusterd_volinfo_new (&new_volinfo); if (ret) goto out; - strncpy (new_volinfo->volname, volname, sizeof (new_volinfo->volname)); + strncpy (new_volinfo->volname, volname, strlen (volname)); memset (key, 0, sizeof (key)); snprintf (key, sizeof (key), "%s%d.type", prefix, count); @@ -7129,19 +7129,6 @@ glusterd_friend_remove_cleanup_vols (uuid_t uuid) cds_list_for_each_entry_safe (volinfo, tmp_volinfo, &priv->volumes, vol_list) { - if (glusterd_friend_contains_vol_bricks (volinfo, uuid) == 2) { - gf_msg (THIS->name, GF_LOG_INFO, 0, - GD_MSG_STALE_VOL_DELETE_INFO, - "Deleting stale volume %s", volinfo->volname); - ret = glusterd_delete_volume (volinfo); - if (ret) { - gf_msg (THIS->name, GF_LOG_ERROR, 0, - GD_MSG_STALE_VOL_REMOVE_FAIL, - "Error deleting stale volume"); - goto out; - } - } - if (!glusterd_friend_contains_vol_bricks (volinfo, MY_UUID)) { /*Stop snapd daemon service if snapd daemon is running*/ @@ -7155,6 +7142,20 @@ glusterd_friend_remove_cleanup_vols (uuid_t uuid) } } } + + if (glusterd_friend_contains_vol_bricks (volinfo, uuid) == 2) { + gf_msg (THIS->name, GF_LOG_INFO, 0, + GD_MSG_STALE_VOL_DELETE_INFO, + "Deleting stale volume %s", volinfo->volname); + ret = glusterd_delete_volume (volinfo); + if (ret) { + gf_msg (THIS->name, GF_LOG_ERROR, 0, + GD_MSG_STALE_VOL_REMOVE_FAIL, + "Error deleting stale volume"); + goto out; + } + } + } /* Reconfigure all daemon services upon peer detach */ @@ -7386,7 +7387,7 @@ glusterd_defrag_info_set (glusterd_volinfo_t *volinfo, dict_t *dict, int cmd, rebal->defrag_status = status; rebal->op = op; - if (!rebal->rebalance_id) + if (gf_uuid_is_null (rebal->rebalance_id)) return; if (is_origin_glusterd (dict)) { -- cgit