summaryrefslogtreecommitdiff
path: root/apps
diff options
context:
space:
mode:
authorJoshua Colp <jcolp@digium.com>2017-05-13 16:40:00 +0000
committerJoshua Colp <jcolp@digium.com>2017-05-16 14:25:23 +0000
commit5a7af00e80b9f360a11fcbbc6c6b6dfd2ee478a6 (patch)
tree6f5b088ad13c1451d1e8421e57b9cd1a9a2d3434 /apps
parentce4d8dac91631599452a9c7aa9c81001704afb62 (diff)
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
Diffstat (limited to 'apps')
-rw-r--r--apps/app_chanspy.c16
-rw-r--r--apps/app_dial.c6
-rw-r--r--apps/app_disa.c10
-rw-r--r--apps/app_dumpchan.c4
-rw-r--r--apps/app_externalivr.c6
5 files changed, 18 insertions, 24 deletions
diff --git a/apps/app_chanspy.c b/apps/app_chanspy.c
index 4814f4ce5..354b9ea7d 100644
--- a/apps/app_chanspy.c
+++ b/apps/app_chanspy.c
@@ -693,9 +693,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;
@@ -825,9 +823,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);
@@ -921,7 +917,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;
@@ -934,7 +930,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)) {
@@ -977,7 +973,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)) {
@@ -1196,7 +1192,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);
diff --git a/apps/app_dial.c b/apps/app_dial.c
index 79e2a9b0b..847a095f4 100644
--- a/apps/app_dial.c
+++ b/apps/app_dial.c
@@ -2855,7 +2855,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;
@@ -2919,13 +2919,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]);
diff --git a/apps/app_disa.c b/apps/app_disa.c
index 8dc61ff64..cceb5541d 100644
--- a/apps/app_disa.c
+++ b/apps/app_disa.c
@@ -208,7 +208,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 */
@@ -224,7 +224,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;
}
@@ -232,7 +232,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;
}
@@ -261,7 +261,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;
@@ -357,7 +357,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;
diff --git a/apps/app_dumpchan.c b/apps/app_dumpchan.c
index 0789ce06e..bec778817 100644
--- a/apps/app_dumpchan.c
+++ b/apps/app_dumpchan.c
@@ -88,8 +88,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"
@@ -166,7 +164,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;
}
diff --git a/apps/app_externalivr.c b/apps/app_externalivr.c
index c2224b44b..84267a5ea 100644
--- a/apps/app_externalivr.c
+++ b/apps/app_externalivr.c
@@ -642,9 +642,9 @@ static int eivr_comm(struct ast_channel *chan, struct ivr_localuser *u,
waitfds[0] = ast_iostream_get_fd(eivr_commands);
waitfds[1] = eivr_errors ? ast_iostream_get_fd(eivr_errors) : -1;
- 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)) {