]> git.ipfire.org Git - thirdparty/asterisk.git/commitdiff
cdr_pgsql: Fix crash when the module fails to load multiple times.
authorchrsmj <52975048+chrsmj@users.noreply.github.com>
Thu, 16 May 2024 20:12:51 +0000 (14:12 -0600)
committerAsterisk Development Team <asteriskteam@digium.com>
Thu, 11 Jul 2024 13:23:24 +0000 (13:23 +0000)
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: #736
(cherry picked from commit 735330bbd1a6290efdc7d1d69fe27d7e9083af37)

cdr/cdr_pgsql.c

index b189e0952e3e7b60649f3ff2542a9303ce295193..58ee7c1c5e0ce05648f6f9b1771e52aa21427ed7 100644 (file)
@@ -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)