Skip to content

Commit

Permalink
cdr_pgsql: Fix crash when the module fails to load multiple times.
Browse files Browse the repository at this point in the history
Missing or corrupt cdr_pgsql.conf configuration file can cause the
second attempt to load the PostgreSQL CDR module to crash Asterisk via
the Command Line Interface because a null CLI command is registered on
the first failed attempt to load the module.

Resolves: asterisk#736
  • Loading branch information
chrsmj authored and asterisk-org-access-app[bot] committed Jun 5, 2024
1 parent e1db302 commit f789b77
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions cdr/cdr_pgsql.c
Original file line number Diff line number Diff line change
Expand Up @@ -783,12 +783,23 @@ static int config_module(int reload)

static int load_module(void)
{
ast_cli_register_multiple(cdr_pgsql_status_cli, sizeof(cdr_pgsql_status_cli) / sizeof(struct ast_cli_entry));
int res;

if (config_module(0)) {
return AST_MODULE_LOAD_DECLINE;
res = AST_MODULE_LOAD_DECLINE;
} else if (ast_cdr_register(name, ast_module_info->description, pgsql_log)) {
res = AST_MODULE_LOAD_DECLINE;
} else if (ast_cli_register_multiple(cdr_pgsql_status_cli, ARRAY_LEN(cdr_pgsql_status_cli))) {
res = AST_MODULE_LOAD_DECLINE;
} else {
res = AST_MODULE_LOAD_SUCCESS;
}

if (res != AST_MODULE_LOAD_SUCCESS) {
unload_module();
}
return ast_cdr_register(name, ast_module_info->description, pgsql_log)
? AST_MODULE_LOAD_DECLINE : 0;

return res;
}

static int reload(void)
Expand Down

0 comments on commit f789b77

Please sign in to comment.