From 0153fcfcbd0e442824ec9bc19122a253512e98ea Mon Sep 17 00:00:00 2001 From: Iraj Jamali Date: Mon, 24 Sep 2018 16:44:45 +0530 Subject: mgmt/glusterd: NULL pointer dereferencing clang fix Added checks to avoid NULL pointer dereferencing Updates: bz#1622665 Change-Id: I745c1f3ba4df0e486ce99301843f9f13d01c00e0 Signed-off-by: Iraj Jamali --- xlators/mgmt/glusterd/src/glusterd-brick-ops.c | 31 +++++++++++++------------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/xlators/mgmt/glusterd/src/glusterd-brick-ops.c b/xlators/mgmt/glusterd/src/glusterd-brick-ops.c index 2698ef783a..8719bbf3fd 100644 --- a/xlators/mgmt/glusterd/src/glusterd-brick-ops.c +++ b/xlators/mgmt/glusterd/src/glusterd-brick-ops.c @@ -721,19 +721,20 @@ subvol_matcher_update(int *subvols, glusterd_volinfo_t *volinfo, glusterd_brickinfo_t *tmp = NULL; int32_t sub_volume = 0; int pos = 0; - - cds_list_for_each_entry(tmp, &volinfo->bricks, brick_list) - { - if (strcmp(tmp->hostname, brickinfo->hostname) || - strcmp(tmp->path, brickinfo->path)) { - pos++; - continue; + if (subvols) { + cds_list_for_each_entry(tmp, &volinfo->bricks, brick_list) + { + if (strcmp(tmp->hostname, brickinfo->hostname) || + strcmp(tmp->path, brickinfo->path)) { + pos++; + continue; + } + gf_msg_debug(THIS->name, 0, LOGSTR_FOUND_BRICK, brickinfo->hostname, + brickinfo->path, volinfo->volname); + sub_volume = (pos / volinfo->dist_leaf_count); + subvols[sub_volume]++; + break; } - gf_msg_debug(THIS->name, 0, LOGSTR_FOUND_BRICK, brickinfo->hostname, - brickinfo->path, volinfo->volname); - sub_volume = (pos / volinfo->dist_leaf_count); - subvols[sub_volume]++; - break; } } @@ -745,7 +746,7 @@ subvol_matcher_verify(int *subvols, glusterd_volinfo_t *volinfo, char *err_str, int ret = 0; int count = volinfo->replica_count - replica_count; - if (replica_count) { + if (replica_count && subvols) { for (i = 0; i < volinfo->subvol_count; i++) { if (subvols[i] != count) { ret = -1; @@ -760,7 +761,7 @@ subvol_matcher_verify(int *subvols, glusterd_volinfo_t *volinfo, char *err_str, } do { - if (subvols[i] % volinfo->dist_leaf_count == 0) { + if (subvols && (subvols[i] % volinfo->dist_leaf_count == 0)) { continue; } else { ret = -1; @@ -1244,7 +1245,7 @@ _glusterd_restart_gsync_session(dict_t *this, char *key, data_t *value, &slave_url, &slave_host, &slave_vol, &conf_path, errmsg); if (ret) { - if (*errmsg) + if (errmsg && *errmsg) gf_msg("glusterd", GF_LOG_ERROR, 0, GD_MSG_SLAVE_CONFPATH_DETAILS_FETCH_FAIL, "%s", *errmsg); else -- cgit