asterisk: Audit locking of channel when manipulating flags.

When manipulating flags on a channel the channel has to be
locked to guarantee that nothing else is also manipulating
the flags. This change introduces locking where necessary to
guarantee this. It also adds helper functions that manipulate
channel flags and lock to reduce repeated code.

ASTERISK-26789

Change-Id: I489280662dba0f4c50981bfc5b5a7073fef2db10
This commit is contained in:
Joshua Colp
2017-05-13 16:40:00 +00:00
parent 6383d9214a
commit 1618203964
15 changed files with 96 additions and 55 deletions

View File

@@ -676,9 +676,7 @@ static int channel_spy(struct ast_channel *chan, struct ast_autochan *spyee_auto
}
}
ast_channel_lock(chan);
ast_set_flag(ast_channel_flags(chan), AST_FLAG_END_DTMF_ONLY);
ast_channel_unlock(chan);
ast_channel_set_flag(chan, AST_FLAG_END_DTMF_ONLY);
csth.volfactor = *volfactor;
@@ -808,9 +806,7 @@ static int channel_spy(struct ast_channel *chan, struct ast_autochan *spyee_auto
else
ast_deactivate_generator(chan);
ast_channel_lock(chan);
ast_clear_flag(ast_channel_flags(chan), AST_FLAG_END_DTMF_ONLY);
ast_channel_unlock(chan);
ast_channel_clear_flag(chan, AST_FLAG_END_DTMF_ONLY);
if (ast_test_flag(flags, OPTION_WHISPER | OPTION_BARGE | OPTION_DTMF_SWITCH_MODES)) {
ast_audiohook_lock(&csth.whisper_audiohook);
@@ -904,7 +900,7 @@ static int common_exec(struct ast_channel *chan, struct ast_flags *flags,
if (ast_channel_state(chan) != AST_STATE_UP)
ast_answer(chan);
ast_set_flag(ast_channel_flags(chan), AST_FLAG_SPYING); /* so nobody can spy on us while we are spying */
ast_channel_set_flag(chan, AST_FLAG_SPYING);
waitms = 100;
@@ -917,7 +913,7 @@ static int common_exec(struct ast_channel *chan, struct ast_flags *flags,
if (!res)
res = ast_waitstream(chan, "");
else if (res < 0) {
ast_clear_flag(ast_channel_flags(chan), AST_FLAG_SPYING);
ast_channel_clear_flag(chan, AST_FLAG_SPYING);
break;
}
if (!ast_strlen_zero(exitcontext)) {
@@ -960,7 +956,7 @@ static int common_exec(struct ast_channel *chan, struct ast_flags *flags,
res = ast_waitfordigit(chan, waitms);
if (res < 0) {
iter = ast_channel_iterator_destroy(iter);
ast_clear_flag(ast_channel_flags(chan), AST_FLAG_SPYING);
ast_channel_clear_flag(chan, AST_FLAG_SPYING);
break;
}
if (!ast_strlen_zero(exitcontext)) {
@@ -1179,7 +1175,7 @@ static int common_exec(struct ast_channel *chan, struct ast_flags *flags,
}
exit:
ast_clear_flag(ast_channel_flags(chan), AST_FLAG_SPYING);
ast_channel_clear_flag(chan, AST_FLAG_SPYING);
ast_channel_setoption(chan, AST_OPTION_TXGAIN, &zero_volume, sizeof(zero_volume), 0);

View File

@@ -2870,7 +2870,7 @@ static int dial_exec_full(struct ast_channel *chan, const char *data, struct ast
ast_log(LOG_ERROR, "error streaming file '%s' to callee\n", opt_args[OPT_ARG_ANNOUNCE]);
}
ast_set_flag(ast_channel_flags(peer), AST_FLAG_END_DTMF_ONLY);
ast_channel_set_flag(peer, AST_FLAG_END_DTMF_ONLY);
while (ast_channel_stream(peer)) {
int ms;
@@ -2934,13 +2934,13 @@ static int dial_exec_full(struct ast_channel *chan, const char *data, struct ast
}
ast_sched_runq(ast_channel_sched(peer));
}
ast_clear_flag(ast_channel_flags(peer), AST_FLAG_END_DTMF_ONLY);
ast_channel_clear_flag(peer, AST_FLAG_END_DTMF_ONLY);
}
if (chan && peer && ast_test_flag64(&opts, OPT_GOTO) && !ast_strlen_zero(opt_args[OPT_ARG_GOTO])) {
/* chan and peer are going into the PBX; as such neither are considered
* outgoing channels any longer */
ast_clear_flag(ast_channel_flags(chan), AST_FLAG_OUTGOING);
ast_channel_clear_flag(chan, AST_FLAG_OUTGOING);
ast_replace_subargument_delimiter(opt_args[OPT_ARG_GOTO]);
ast_parseable_goto(chan, opt_args[OPT_ARG_GOTO]);

View File

@@ -210,7 +210,7 @@ static int disa_exec(struct ast_channel *chan, const char *data)
play_dialtone(chan, args.mailbox);
ast_set_flag(ast_channel_flags(chan), AST_FLAG_END_DTMF_ONLY);
ast_channel_set_flag(chan, AST_FLAG_END_DTMF_ONLY);
for (;;) {
/* if outa time, give em reorder */
@@ -226,7 +226,7 @@ static int disa_exec(struct ast_channel *chan, const char *data)
}
if (!(f = ast_read(chan))) {
ast_clear_flag(ast_channel_flags(chan), AST_FLAG_END_DTMF_ONLY);
ast_channel_clear_flag(chan, AST_FLAG_END_DTMF_ONLY);
return -1;
}
@@ -234,7 +234,7 @@ static int disa_exec(struct ast_channel *chan, const char *data)
if (f->data.uint32)
ast_channel_hangupcause_set(chan, f->data.uint32);
ast_frfree(f);
ast_clear_flag(ast_channel_flags(chan), AST_FLAG_END_DTMF_ONLY);
ast_channel_clear_flag(chan, AST_FLAG_END_DTMF_ONLY);
return -1;
}
@@ -263,7 +263,7 @@ static int disa_exec(struct ast_channel *chan, const char *data)
fp = fopen(args.passcode,"r");
if (!fp) {
ast_log(LOG_WARNING,"DISA password file %s not found on chan %s\n",args.passcode,ast_channel_name(chan));
ast_clear_flag(ast_channel_flags(chan), AST_FLAG_END_DTMF_ONLY);
ast_channel_clear_flag(chan, AST_FLAG_END_DTMF_ONLY);
return -1;
}
pwline[0] = 0;
@@ -359,7 +359,7 @@ static int disa_exec(struct ast_channel *chan, const char *data)
}
}
ast_clear_flag(ast_channel_flags(chan), AST_FLAG_END_DTMF_ONLY);
ast_channel_clear_flag(chan, AST_FLAG_END_DTMF_ONLY);
if (k == 3) {
int recheck = 0;

View File

@@ -90,8 +90,6 @@ static int serialize_showchan(struct ast_channel *c, char *buf, size_t size)
ast_channel_lock(c);
bridge = ast_channel_get_bridge(c);
ast_channel_unlock(c);
snprintf(buf,size,
"Name= %s\n"
"Type= %s\n"
@@ -168,7 +166,7 @@ static int serialize_showchan(struct ast_channel *c, char *buf, size_t size)
ast_channel_appl(c) ? ast_channel_appl(c) : "(N/A)",
ast_channel_data(c) ? S_OR(ast_channel_data(c), "(Empty)") : "(None)",
(ast_test_flag(ast_channel_flags(c), AST_FLAG_BLOCKING) ? ast_channel_blockproc(c) : "(Not Blocking)"));
ast_channel_unlock(c);
ao2_cleanup(bridge);
return 0;
}

View File

@@ -645,9 +645,9 @@ static int eivr_comm(struct ast_channel *chan, struct ivr_localuser *u,
setvbuf(eivr_errors, NULL, _IONBF, 0);
}
while (1) {
if (ast_test_flag(ast_channel_flags(chan), AST_FLAG_ZOMBIE)) {
ast_chan_log(LOG_ERROR, chan, "Is a zombie\n");
while (1) {
if (ast_test_flag(ast_channel_flags(chan), AST_FLAG_ZOMBIE)) {
ast_chan_log(LOG_ERROR, chan, "Is a zombie\n");
break;
}
if (!hangup_info_sent && !(ast_test_flag(&flags, run_dead)) && ast_check_hangup(chan)) {