From b0f98ef84ac19092c785c881f92fd01371d754dd Mon Sep 17 00:00:00 2001 From: Vlad Patrascu Date: Mon, 3 Jul 2023 13:09:35 +0300 Subject: [PATCH] clusterer: fix crash after MI reload The crash was caused by accessing a dangling pointer to the capability structure after it was freed. Thanks to Suchi Sahoo from Five9 for reporting! (cherry picked from commit cb8d63193b84909e1c238418dc3e80825ebb746e) --- modules/clusterer/clusterer.c | 3 +++ modules/clusterer/sharing_tags.c | 23 +++++++++++++++++++++++ modules/clusterer/sharing_tags.h | 2 ++ 3 files changed, 28 insertions(+) diff --git a/modules/clusterer/clusterer.c b/modules/clusterer/clusterer.c index 2f97ee0acb3..7cf82d67843 100644 --- a/modules/clusterer/clusterer.c +++ b/modules/clusterer/clusterer.c @@ -1795,6 +1795,9 @@ int preserve_reg_caps(cluster_info_t *new_info) LM_ERR("Failed to duplicate capabilities info\n"); return -1; } + + update_shtags_sync_status_cap(cl->cluster_id, + new_cl->capabilities); } return 0; diff --git a/modules/clusterer/sharing_tags.c b/modules/clusterer/sharing_tags.c index 1625812f3c5..32d47e7136e 100644 --- a/modules/clusterer/sharing_tags.c +++ b/modules/clusterer/sharing_tags.c @@ -596,6 +596,29 @@ int shtag_set_sync_status(str *tag_name, int cluster_id, str *capability, return 0; } +void update_shtags_sync_status_cap(int cluster_id, struct local_cap *new_caps) +{ + struct sharing_tag *tag; + struct shtag_sync_status *status; + struct local_cap *cap; + + lock_start_write(shtags_lock); + + for (tag = *shtags_list; tag; tag = tag->next) { + if (tag->cluster_id != cluster_id) + continue; + + for (status=tag->sync_status; status; status=status->next) + for (cap = new_caps; cap; cap = cap->next) + if (!str_strcmp(&cap->reg.name, &status->capability->reg.name)) { + status->capability = cap; + break; + } + } + + lock_stop_write(shtags_lock); +} + int shtag_sync_all_backup(int cluster_id, str *capability) { struct sharing_tag *tag; diff --git a/modules/clusterer/sharing_tags.h b/modules/clusterer/sharing_tags.h index 49096c71e37..ae7a26e411c 100644 --- a/modules/clusterer/sharing_tags.h +++ b/modules/clusterer/sharing_tags.h @@ -70,6 +70,8 @@ int shtag_set_sync_status(str *tag_name, int cluster_id, str *capability, int shtag_sync_all_backup(int cluster_id, str *capability); +void update_shtags_sync_status_cap(int cluster_id, struct local_cap *new_caps); + /* script vars related functions */ int var_get_sh_tag(struct sip_msg *msg, pv_param_t *param, pv_value_t *res);