From d7a01afa5041f5721bba7c60de64d1b5fd2c4e51 Mon Sep 17 00:00:00 2001 From: Sean Bright Date: Mon, 9 Oct 2023 09:32:57 -0400 Subject: [PATCH] func_curl.c: Ensure channel is locked when manipulating datastores. (cherry picked from commit acb2348f906a454796635ac606dafe613a1a0d47) --- funcs/func_curl.c | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/funcs/func_curl.c b/funcs/func_curl.c index c51d2738d2..37cd636809 100644 --- a/funcs/func_curl.c +++ b/funcs/func_curl.c @@ -341,16 +341,19 @@ static int acf_curlopt_write(struct ast_channel *chan, const char *cmd, char *na enum optiontype ot; if (chan) { + ast_channel_lock(chan); if (!(store = ast_channel_datastore_find(chan, &curl_info, NULL))) { /* Create a new datastore */ if (!(store = ast_datastore_alloc(&curl_info, NULL))) { ast_log(LOG_ERROR, "Unable to allocate new datastore. Cannot set any CURL options\n"); + ast_channel_unlock(chan); return -1; } if (!(list = ast_calloc(1, sizeof(*list)))) { ast_log(LOG_ERROR, "Unable to allocate list head. Cannot set any CURL options\n"); ast_datastore_free(store); + ast_channel_unlock(chan); return -1; } @@ -360,6 +363,7 @@ static int acf_curlopt_write(struct ast_channel *chan, const char *cmd, char *na } else { list = store->data; } + ast_channel_unlock(chan); } else { /* Populate the global structure */ list = &global_curl_info; @@ -472,9 +476,17 @@ static int acf_curlopt_helper(struct ast_channel *chan, const char *cmd, char *d return -1; } - if (chan && (store = ast_channel_datastore_find(chan, &curl_info, NULL))) { - list[0] = store->data; - list[1] = &global_curl_info; + if (chan) { + /* If we have a channel, we want to read the options set there before + falling back to the global settings */ + ast_channel_lock(chan); + store = ast_channel_datastore_find(chan, &curl_info, NULL); + ast_channel_unlock(chan); + + if (store) { + list[0] = store->data; + list[1] = &global_curl_info; + } } for (i = 0; i < 2; i++) { -- 2.47.2