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

@@ -1545,7 +1545,7 @@ static int waitstream_core(struct ast_channel *c,
reverse = "";
/* Switch the channel to end DTMF frame only. waitstream_core doesn't care about the start of DTMF. */
ast_set_flag(ast_channel_flags(c), AST_FLAG_END_DTMF_ONLY);
ast_channel_set_flag(c, AST_FLAG_END_DTMF_ONLY);
if (ast_test_flag(ast_channel_flags(c), AST_FLAG_MASQ_NOSTREAM))
orig_chan_name = ast_strdupa(ast_channel_name(c));
@@ -1577,7 +1577,7 @@ static int waitstream_core(struct ast_channel *c,
res = ast_waitfor(c, ms);
if (res < 0) {
ast_log(LOG_WARNING, "Select failed (%s)\n", strerror(errno));
ast_clear_flag(ast_channel_flags(c), AST_FLAG_END_DTMF_ONLY);
ast_channel_clear_flag(c, AST_FLAG_END_DTMF_ONLY);
return res;
}
} else {
@@ -1588,11 +1588,11 @@ static int waitstream_core(struct ast_channel *c,
if (errno == EINTR)
continue;
ast_log(LOG_WARNING, "Wait failed (%s)\n", strerror(errno));
ast_clear_flag(ast_channel_flags(c), AST_FLAG_END_DTMF_ONLY);
ast_channel_clear_flag(c, AST_FLAG_END_DTMF_ONLY);
return -1;
} else if (outfd > -1) { /* this requires cmdfd set */
/* The FD we were watching has something waiting */
ast_clear_flag(ast_channel_flags(c), AST_FLAG_END_DTMF_ONLY);
ast_channel_clear_flag(c, AST_FLAG_END_DTMF_ONLY);
return 1;
}
/* if rchan is set, it is 'c' */
@@ -1601,7 +1601,7 @@ static int waitstream_core(struct ast_channel *c,
if (res > 0) {
struct ast_frame *fr = ast_read(c);
if (!fr) {
ast_clear_flag(ast_channel_flags(c), AST_FLAG_END_DTMF_ONLY);
ast_channel_clear_flag(c, AST_FLAG_END_DTMF_ONLY);
return -1;
}
switch (fr->frametype) {
@@ -1612,7 +1612,7 @@ static int waitstream_core(struct ast_channel *c,
S_COR(ast_channel_caller(c)->id.number.valid, ast_channel_caller(c)->id.number.str, NULL))) {
res = fr->subclass.integer;
ast_frfree(fr);
ast_clear_flag(ast_channel_flags(c), AST_FLAG_END_DTMF_ONLY);
ast_channel_clear_flag(c, AST_FLAG_END_DTMF_ONLY);
return res;
}
} else {
@@ -1628,7 +1628,7 @@ static int waitstream_core(struct ast_channel *c,
"Break");
ast_frfree(fr);
ast_clear_flag(ast_channel_flags(c), AST_FLAG_END_DTMF_ONLY);
ast_channel_clear_flag(c, AST_FLAG_END_DTMF_ONLY);
return res;
}
}
@@ -1645,7 +1645,7 @@ static int waitstream_core(struct ast_channel *c,
"Break");
res = fr->subclass.integer;
ast_frfree(fr);
ast_clear_flag(ast_channel_flags(c), AST_FLAG_END_DTMF_ONLY);
ast_channel_clear_flag(c, AST_FLAG_END_DTMF_ONLY);
return res;
case AST_CONTROL_STREAM_REVERSE:
if (!skip_ms) {
@@ -1663,7 +1663,7 @@ static int waitstream_core(struct ast_channel *c,
case AST_CONTROL_BUSY:
case AST_CONTROL_CONGESTION:
ast_frfree(fr);
ast_clear_flag(ast_channel_flags(c), AST_FLAG_END_DTMF_ONLY);
ast_channel_clear_flag(c, AST_FLAG_END_DTMF_ONLY);
return -1;
case AST_CONTROL_RINGING:
case AST_CONTROL_ANSWER:
@@ -1700,7 +1700,7 @@ static int waitstream_core(struct ast_channel *c,
ast_sched_runq(ast_channel_sched(c));
}
ast_clear_flag(ast_channel_flags(c), AST_FLAG_END_DTMF_ONLY);
ast_channel_clear_flag(c, AST_FLAG_END_DTMF_ONLY);
return (err || ast_channel_softhangup_internal_flag(c)) ? -1 : 0;
}