diff options
author | russell <russell@f38db490-d61c-443f-a65b-d21fe96a405b> | 2009-03-11 21:42:58 +0000 |
---|---|---|
committer | russell <russell@f38db490-d61c-443f-a65b-d21fe96a405b> | 2009-03-11 21:42:58 +0000 |
commit | 5e7e50f861dcc72b4be6c4754341c6697c867098 (patch) | |
tree | 09c71ad76b961b6b7973e9edec5d32ffd07a0d85 /main | |
parent | c8544de66ab4ae15e56e53686c09d58adcd01189 (diff) |
Make code that updates BRIDGEPEER variable thread-safe.
It is not safe to read the name field of an ast_channel without the channel
locked. This patch fixes some places in channel.c where this was being done,
and lead to crashes related to masquerades.
(closes issue #14623)
Reported by: guillecabeza
git-svn-id: http://svn.digium.com/svn/asterisk/branches/1.4@181423 f38db490-d61c-443f-a65b-d21fe96a405b
Diffstat (limited to 'main')
-rw-r--r-- | main/channel.c | 44 |
1 files changed, 30 insertions, 14 deletions
diff --git a/main/channel.c b/main/channel.c index 07bc5d474..475942163 100644 --- a/main/channel.c +++ b/main/channel.c @@ -4060,6 +4060,29 @@ static enum ast_bridge_result ast_generic_bridge(struct ast_channel *c0, struct return res; } +static void update_bridgepeer(struct ast_channel *c0, struct ast_channel *c1) +{ + const char *c0_name; + const char *c1_name; + + ast_channel_lock(c1); + c1_name = ast_strdupa(c1->name); + ast_channel_unlock(c1); + + ast_channel_lock(c0); + if (!ast_strlen_zero(pbx_builtin_getvar_helper(c0, "BRIDGEPEER"))) { + pbx_builtin_setvar_helper(c0, "BRIDGEPEER", c1_name); + } + c0_name = ast_strdupa(c0->name); + ast_channel_unlock(c0); + + ast_channel_lock(c1); + if (!ast_strlen_zero(pbx_builtin_getvar_helper(c1, "BRIDGEPEER"))) { + pbx_builtin_setvar_helper(c1, "BRIDGEPEER", c0_name); + } + ast_channel_unlock(c1); +} + /*! \brief Bridge two channels together */ enum ast_bridge_result ast_channel_bridge(struct ast_channel *c0, struct ast_channel *c1, struct ast_bridge_config *config, struct ast_frame **fo, struct ast_channel **rc) @@ -4176,7 +4199,7 @@ enum ast_bridge_result ast_channel_bridge(struct ast_channel *c0, struct ast_cha res = 0; break; } - + if (!to) { if (time_left_ms >= 5000 && config->warning_sound && config->play_warning && ast_test_flag(config, AST_FEATURE_WARNING_ACTIVE)) { int t = (time_left_ms + 500) / 1000; /* round to nearest second */ @@ -4204,7 +4227,7 @@ enum ast_bridge_result ast_channel_bridge(struct ast_channel *c0, struct ast_cha ast_log(LOG_DEBUG, "Unbridge signal received. Ending native bridge.\n"); continue; } - + /* Stop if we're a zombie or need a soft hangup */ if (ast_test_flag(c0, AST_FLAG_ZOMBIE) || ast_check_hangup_locked(c0) || ast_test_flag(c1, AST_FLAG_ZOMBIE) || ast_check_hangup_locked(c1)) { @@ -4221,13 +4244,9 @@ enum ast_bridge_result ast_channel_bridge(struct ast_channel *c0, struct ast_cha ast_check_hangup(c1) ? "Yes" : "No"); break; } - - /* See if the BRIDGEPEER variable needs to be updated */ - if (!ast_strlen_zero(pbx_builtin_getvar_helper(c0, "BRIDGEPEER"))) - pbx_builtin_setvar_helper(c0, "BRIDGEPEER", c1->name); - if (!ast_strlen_zero(pbx_builtin_getvar_helper(c1, "BRIDGEPEER"))) - pbx_builtin_setvar_helper(c1, "BRIDGEPEER", c0->name); - + + update_bridgepeer(c0, c1); + if (c0->tech->bridge && (config->timelimit == 0) && (c0->tech->bridge == c1->tech->bridge) && @@ -4278,7 +4297,7 @@ enum ast_bridge_result ast_channel_bridge(struct ast_channel *c0, struct ast_cha break; } } - + if (((c0->writeformat != c1->readformat) || (c0->readformat != c1->writeformat) || (c0->nativeformats != o0nativeformats) || (c1->nativeformats != o1nativeformats)) && !(c0->generator || c1->generator)) { @@ -4299,10 +4318,7 @@ enum ast_bridge_result ast_channel_bridge(struct ast_channel *c0, struct ast_cha o1nativeformats = c1->nativeformats; } - if (!ast_strlen_zero(pbx_builtin_getvar_helper(c0, "BRIDGEPEER"))) - pbx_builtin_setvar_helper(c0, "BRIDGEPEER", c1->name); - if (!ast_strlen_zero(pbx_builtin_getvar_helper(c1, "BRIDGEPEER"))) - pbx_builtin_setvar_helper(c1, "BRIDGEPEER", c0->name); + update_bridgepeer(c0, c1); res = ast_generic_bridge(c0, c1, config, fo, rc, config->nexteventts); if (res != AST_BRIDGE_RETRY) { |