Skip to content

Commit

Permalink
clusterer: Fix some startup corner-cases (crashes)
Browse files Browse the repository at this point in the history
The first extra check fixes a crash in 'db_mode = 0', if only
'neighbor_node_info' is given, so cl->current_node will be NULL.

The second extra check prevents:

(gdb) bt full
0  check_seed_flag (cl_list=<optimized out>) at node_info.c:307
1  load_db_info (dr_dbf=dr_dbf@entry=0x7f2e65996300 <dr_dbf>,
     db_hdl=<optimized out>, db_table=db_table@entry=0x7f2e65993370
     <db_table>, cl_list=<optimized out>) at node_info.c:485
2  mod_init () at clusterer_mod.c:408

Fixes #2086
  • Loading branch information
liviuchircu committed Jul 2, 2020
1 parent 61e523a commit 0b609f0
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
9 changes: 8 additions & 1 deletion modules/clusterer/clusterer_mod.c
Expand Up @@ -381,12 +381,19 @@ static int mod_init(void)
*cluster_list = NULL;
} else {
/* sanity check of my_node_id if node_id also set in a my_node_info param */
for (cl = *cluster_list; cl; cl = cl->next)
for (cl = *cluster_list; cl; cl = cl->next) {
if (!cl->current_node) {
LM_ERR("current node is not part of cluster %d\n",
cl->cluster_id);
goto error;
}

if (cl->current_node->node_id != current_id) {
LM_ERR("Bad 'my_node_id' parameter, value: %d different than"
" the node_id property in the 'my_node_info' parameter\n", current_id);
goto error;
}
}
}

if (db_mode) {
Expand Down
10 changes: 6 additions & 4 deletions modules/clusterer/node_info.c
Expand Up @@ -304,7 +304,9 @@ static void check_seed_flag(cluster_info_t **cl_list)
for (n = cl->node_list; n; n = n->next)
if (n->flags & NODE_IS_SEED)
break;
if (!n && !(cl->current_node->flags & NODE_IS_SEED)) {

if (!n && cl->current_node &&
!(cl->current_node->flags & NODE_IS_SEED)) {
LM_NOTICE("No seed node defined in cluster: %d! Some clustering "
"capabilities might not be able to sync data\n", cl->cluster_id);
}
Expand All @@ -320,7 +322,7 @@ int load_db_info(db_func_t *dr_dbf, db_con_t* db_hdl, str *db_table,
int no_clusters;
int i;
int rc;
node_info_t *new_info = NULL;
node_info_t *_ = NULL;
db_key_t columns[NO_DB_COLS]; /* the columns from the db table */
db_res_t *res = NULL;
db_row_t *row;
Expand Down Expand Up @@ -376,7 +378,7 @@ int load_db_info(db_func_t *dr_dbf, db_con_t* db_hdl, str *db_table,
}

if (RES_ROW_N(res) == 0) {
LM_WARN("No nodes found in cluster\n");
LM_WARN("Current node does not belong to any cluster\n");
return 1;
}

Expand Down Expand Up @@ -472,7 +474,7 @@ int load_db_info(db_func_t *dr_dbf, db_con_t* db_hdl, str *db_table,
strlen(str_vals[STR_VALS_DESCRIPTION_COL].s) : 0;

/* add info to backing list */
if ((rc = add_node_info(&new_info, cl_list, int_vals, str_vals)) != 0) {
if ((rc = add_node_info(&_, cl_list, int_vals, str_vals)) != 0) {
LM_ERR("Unable to add node info to backing list\n");
if (rc < 0)
return -1;
Expand Down

0 comments on commit 0b609f0

Please sign in to comment.