Fix crash during CDR update.

The ast_cdr_setcid() and ast_cdr_update() were shown in ASTERISK-18836 to
be called by different threads for the same channel.  The channel driver
thread and the PBX thread running dialplan.

* Add lock protection around CDR API calls that access an ast_channel
pointer.

(closes issue ASTERISK-18836)
Reported by: gpluser

Review: https://reviewboard.asterisk.org/r/1628/
........

Merged revisions 348362 from http://svn.asterisk.org/svn/asterisk/branches/1.8
........

Merged revisions 348363 from http://svn.asterisk.org/svn/asterisk/branches/10


git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@348364 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
Richard Mudgett
2011-12-16 21:10:19 +00:00
parent 8baea2b35e
commit b05d4603c4
9 changed files with 109 additions and 30 deletions

View File

@@ -197,17 +197,21 @@ static int cdr_read(struct ast_channel *chan, const char *cmd, char *parse,
{
char *ret;
struct ast_flags flags = { 0 };
struct ast_cdr *cdr = chan ? chan->cdr : NULL;
struct ast_cdr *cdr;
AST_DECLARE_APP_ARGS(args,
AST_APP_ARG(variable);
AST_APP_ARG(options);
);
if (ast_strlen_zero(parse))
if (ast_strlen_zero(parse) || !chan)
return -1;
if (!cdr)
ast_channel_lock(chan);
cdr = chan->cdr;
if (!cdr) {
ast_channel_unlock(chan);
return -1;
}
AST_STANDARD_APP_ARGS(args, parse);
@@ -255,13 +259,14 @@ static int cdr_read(struct ast_channel *chan, const char *cmd, char *parse,
ast_test_flag(&flags, OPT_UNPARSED));
}
ast_channel_unlock(chan);
return ret ? 0 : -1;
}
static int cdr_write(struct ast_channel *chan, const char *cmd, char *parse,
const char *value)
{
struct ast_cdr *cdr = chan ? chan->cdr : NULL;
struct ast_cdr *cdr;
struct ast_flags flags = { 0 };
AST_DECLARE_APP_ARGS(args,
AST_APP_ARG(variable);
@@ -271,8 +276,12 @@ static int cdr_write(struct ast_channel *chan, const char *cmd, char *parse,
if (ast_strlen_zero(parse) || !value || !chan)
return -1;
if (!cdr)
ast_channel_lock(chan);
cdr = chan->cdr;
if (!cdr) {
ast_channel_unlock(chan);
return -1;
}
AST_STANDARD_APP_ARGS(args, parse);
@@ -296,6 +305,7 @@ static int cdr_write(struct ast_channel *chan, const char *cmd, char *parse,
/* No need to worry about the u flag, as all fields for which setting
* 'u' would do anything are marked as readonly. */
ast_channel_unlock(chan);
return 0;
}