]> git.ipfire.org Git - thirdparty/asterisk.git/commitdiff
app_macro: Fix locking around datastore access
authorMatthew Fredrickson <matt@fredricknet.net>
Mon, 21 Aug 2023 16:02:57 +0000 (11:02 -0500)
committerasterisk-org-access-app[bot] <120671045+asterisk-org-access-app[bot]@users.noreply.github.com>
Tue, 22 Aug 2023 13:29:51 +0000 (13:29 +0000)
app_macro sometimes would crash due to datastore list corruption on the
channel because of lack of locking around find and create process for
the macro datastore. This patch locks the channel lock prior to protect
against this problem.

Resolves: #265

apps/app_macro.c

index b426cf8f698bace2590135ffcac4ccba10c57505..565af5546ea6175f3b37f3620292c2ee3a82e44c 100644 (file)
@@ -262,7 +262,7 @@ static int _macro_exec(struct ast_channel *chan, const char *data, int exclusive
        char *save_macro_priority;
        char *save_macro_offset;
        int save_in_subroutine;
-       struct ast_datastore *macro_store = ast_channel_datastore_find(chan, &macro_ds_info, NULL);
+       struct ast_datastore *macro_store;
        int had_infinite_include_error = 0;
        static int deprecation_notice = 0;
 
@@ -277,6 +277,10 @@ static int _macro_exec(struct ast_channel *chan, const char *data, int exclusive
                ast_log(LOG_WARNING, "Dialplan should be updated to use Gosub instead.\n");
        }
 
+       ast_channel_lock(chan);
+
+       macro_store = ast_channel_datastore_find(chan, &macro_ds_info, NULL);
+
        do {
                if (macro_store) {
                        break;
@@ -291,7 +295,6 @@ static int _macro_exec(struct ast_channel *chan, const char *data, int exclusive
        } while (0);
 
        /* does the user want a deeper rabbit hole? */
-       ast_channel_lock(chan);
        if ((s = pbx_builtin_getvar_helper(chan, "MACRO_RECURSION"))) {
                sscanf(s, "%30d", &maxdepth);
        }